tags:

views:

227

answers:

2

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.

+3  A: 

What about diff 11 22 | grep "^[<|>]"?

Jannis
+1. Seems the simplest solution and UNIX was _built_ on the shoulders of pipelines :-)
paxdiablo
grep "^[<>]" # character classes do not need to pipe to split the different possibilities
knittl
knitti: You're right, that's obsolete.
Jannis
It's not obsolete, it's wrong, because that greps lines that start with a pipe too.
wilhelmtell
@wilhelmtell, then we must include \ and / too, i think they are also used somehow (e.g. no newline at end of file)
knittl
+1  A: 

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

justintime