×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

diff to show differed lines only (hiding common lines)

diff to show differed lines only (hiding common lines)

diff to show differed lines only (hiding common lines)

(OP)
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

RE: diff to show differed lines only (hiding common lines)

Hi

I am afraid this works only in GNU diff, 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

RE: diff to show differed lines only (hiding common lines)

(OP)
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

RE: diff to show differed lines only (hiding common lines)

(OP)
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close