6

I have a folder with subfolders that contains text files.

Every now and then I run a script that makes a copy of that folder tree and then creates a new one with fresh info.

After that, having the old version and the new version, I run diff to know what changed between the old version and the new, sending the output to a file:

diff myFiler.old myFolder > diff_report.txt

The question is.

- How can I see diff_report.txt syntax colored?

I don't mean to see the actual output colored like git does when it uses diff, but use such syntax-coloring to see the diff output that has already been saved to a file.

4
  • I'm not sure I understand your last sentence; do you mean syntax coloring based on the type of file itself? (What type of file is that?) Or do you mean simply output coloring, as in red and green for removals and additions?
    – Wildcard
    May 9, 2016 at 19:03
  • 2
    Open it wsith an editor that support diff syntax?
    – joepd
    May 9, 2016 at 19:16
  • Both. I mean red and green for removals etc. Only that the diff output is already saved to a text file. So I want to vizualize that text file with red and green for removals etc. May 9, 2016 at 19:20
  • 1
    @joepd Just discovered that if I rename the file from .txt to .diff, Gedit highlights it. Please put your comment into an answer so I can accept it. May 9, 2016 at 19:44

2 Answers 2

3

Any decent editor is able to highlight diffs conveniently. You can generally persuade your editor by using the .diff extension, or by setting the filetype to diff otherwise.

2

You could hack something together that would read a line of the file, check the first char on the line, and print it in the appropriate color: green if the first char is a +, red if the first char is a -, and the default color (white? black?) otherwise.

Handling the cyan @@ lines would be trickier, since it's not the whole line, but would be possible.


Depending on your OS and whether the appropriate package is available, you could use colordiff.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.