formatting of the diff output
Solution 1
There are two easy ways of doing this, you can either parse the output of diff
or you can use comm
.
diff fileA fileB | grep '>' | sed 's/> *//'
comm -13 fileA fileB
Solution 2
Although more typing than just using comm
, the following provides a demonstration of the --GTYPE-group-format
options:
diff --unchanged-group-format="" --new-group-format="%>" A.txt B.txt
This commmand would only print those lines in B.txt
and not in A.txt
. The first option suppresses common lines. There's no need to use --changed-group-format
(no lines that have different values in each file) or --old-group-format
(everything in A.txt
is also in B.txt
).
Related videos on Youtube
Tomos Williams
Updated on September 18, 2022Comments
-
Tomos Williams over 1 year
I have 2 files that I want to differ. File B is produced appending some new line to file A. I want to highlight the appended data by using
diff
.I would like to avoid printing out the '>' characters and the '10a11,14' of the output below.
Reading the man pages of
diff
I can see that you can specify the formatting of the result ( LFMT ) but I am struggling in producing something useful.Could you help in removing those characters I don't need?
Regards
AFG
diff --left-column A.txt B.txt 10a11,14 > TXT : some text > some text > some text > some text
-
vonbrand over 11 years
diff
also handles the-u
(unidiff) format, it is easier on the eyes.