Reputation: 29353
I have these two files
File: 11
11
456123
File: 22
11
789
Output of diff 11 22
2c2
< 456123
---
> 789
Output to be
< 456123
> 789
I want it to not print the 2c2
and ---
lines. I looked at the man page but could not locate any help. Any ideas? The file has more than 1000 lines.
Upvotes: 1
Views: 2755
Reputation: 5634
What about diff 11 22 | grep "^[<|>]"
?
Update: As knitti pointed out the correct pattern is ^[<>]
Upvotes: 5
Reputation: 3631
Diff has a whole host of useful options like --old-group-format
that are described very briefly in help. They are expanded in http://www.network-theory.co.uk/docs/diff/Line_Group_Formats.html
The following is producing something similar to what you want.
diff 11.txt 22.txt --unchanged-group-format="" --changed-group-format="<%<>%>"
<456123
>789
You might also need to play with --old-group-format=format
(groups hunks containing only lines from the first file) --new-group-format=format
--old-line-format=format
(formats lines just from the first file) and --new-line-format=format
etc
Disclaimer - I have not used this for real before, in fact I have only just understood them. If you have further questions I am happy to look at it later.
Edited to change order of lines
Upvotes: 2