Skip to content

Instantly share code, notes, and snippets.

@stevenh512
Created March 30, 2012 02:22
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevenh512/2245881 to your computer and use it in GitHub Desktop.
Save stevenh512/2245881 to your computer and use it in GitHub Desktop.
Strip color codes from Rails logs
#!/bin/sh
# Strip color codes from Rails logs
# Examples:
# stripcolor test.log > test.log.nocolor # Save a copy of the log without color
# stripcolor test.log | gist # Gist the log
# stripcolor test.log | pbcopy # Copy the log to the clipboard in OSX
# stripcolor test.log | xclip -selection clipboard # Copy log to clipboard in Linux
cat "$@" | sed -r "s/\x1B\[([0-9]{1,3}((;[0-9]{1,3})*)?)?[m|K]//g"
@driehuis
Copy link

Another useful use of this script is in a pipe:

rake rails:upgrade:check | stripcolor | less

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment