how to use diff to only print lines
Hi,
How do I use diff to only print out the actual differences between two text files, and not all those numbers? I have been searching through the man page but don't see a way to do it. Perhaps I have missed something. Thanks |
What version are you using? I'm on Fedora Core 8 and by default it seems it only prints off the lines that are different.
Examples: file1: Code:
this is a line Code:
this is a line Code:
[trickykid@your-momma ~]$ diff file1 file2 |
sorry. i mean only the lines and not those numbers that precede the line. so for your example i would like to see:
Quote:
Quote:
|
Well, I'd say you want to keep the < and > cause they indicate which file the line resides in. It would get sort of messy looking at more lines with differences.
But to remove the other stuff, you could easily grep them out. Code:
diff file1 file2 | grep -v "^---" | grep -v "^[0-9c0-9]" Code:
[trickykid@your-momma ~]$ diff file1 file2 | grep -v "^---" | grep -v "^[0-9c0-9]" |
Thanks. I already used that grep method but I'm not crazy about using it. I thought that diff would be capable of doing this on its own.
|
You could always do the side by side type format which is rather nice and I tend to use it more often, easier to read on smaller files at least:
Code:
[trickykid@your-momma ~]$ diff --suppress-common-lines -y file1 file2 |
Try this:
Code:
diff --line-format=%L file1 file2 |
Quote:
Code:
[trickykid@your-momma ~]$ diff --line-format=%L file1 file2 |
Try comm
You might try comm:
Code:
comm -3 file1.txt file2.txt |
From the comm man page
Quote:
|
Sort, Indeed!
Yes, good point! Use the sort command, first.
Heck, as long as you have sort out of the garage, forget comm and diff. Just use the sort | uniq combo with the -u flag: Code:
sort file1.txt file2.txt |uniq -u > uniq_lines.txt |
All times are GMT -5. The time now is 11:04 PM. |