Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

diff to show differed lines only (hiding common lines)

Status
Not open for further replies.

BauV

Technical User
Aug 25, 2021
8
US
hi,

I am comparing 2 TXT files, each one has millions of rows, to know the differed rows.
How can I hide common rows in the resultant files? please help.

My command: diff -u -w <sort file1) <(sort file2) > file3.res
My file1:
a1 Bala
a2 vup
a3 jivup

My file2:
a1 Bala
a2 Vup
a3 jivup
b1 abc

file3.res from present command:
a1 Bala
a3 jivup
-a2 vup
+a2 Vup
+b1 abc

O/p file that I want to see:(hide all common rows, show only differed rows)
-a2 vup
+a2 Vup
+b1 abc

Cheers,
BauV
 
Hi

I am afraid this works only in GNU [tt]diff[/tt], but give it a try :
Code:
diff --unchanged-line-format= --old-line-format='-%L' --new-line-format='+%L' <(sort file1) <(sort file2) > file3.res


Feherke.
feherke.github.io
 
Thanks Feherke, for your suggestion.
Unfortunately it's not working, my Linux 5.10 says "...illegal option -- unchanged-line-format=".

Even "diff file1.txt file2.txt |grep -E ’<|>’ > outputfile.txt" also says "....illegal option -- E..".
Any further suggestion is appreciable.

Cheers,
BauV
 
hi,

This one worked for me excluding the lines that start with 1 space.
diff file1.txt file2.txt |grep -v '^ ' > outputfile.txt

Cheers,
BauV
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top