I need to save the result of a grep command into a file, but I also want the output file to be formatted and keep the colors just like in the terminal. Is there a way to do that? Maybe make grep save to a some kind of markup language? If it is not possible, is there another tool that can accomplish this task? I am trying to make the search keyword stand out in the output file, exactly like it does in the terminal. |
Depending on what you're wanting to do with the output file, it's possible to add colors to normal text file, because the colors simply come from some special characters. Grep seems to not want to print them when you redirect it to a file, so you need to force it to:
Now, when you print the file to the console it will be printed with the colors, because Bash interprets those characters as "use this color".
However, if you open it in an editor like
The output looks right when I print it using
So if you're wanting to use an editor this probably isn't what you want. |