LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 03-23-2009, 10:18 PM   #1
noir911
Member
 
Registered: Apr 2004
Posts: 682

Rep: Reputation: Disabled
diff two files


I have one file with

Quote:
test
test
test
test
test
NOTtest
another file with
Quote:
test
Is there any way to tell diff to ignore "test" since it appears in both the files and only show "NOTtest" as the diff result since it's not on the other file?
 
Old 03-24-2009, 03:22 AM   #2
SonJelfn
Member
 
Registered: Aug 2003
Location: Sendai, Japan
Distribution: Slackware, Slackware64, Debian
Posts: 63

Rep: Reputation: 17
diff is meant to be used to find all the differences between two files so in your particular case, the differences are pretty big and can't be ignored using only the diff command.

I'm not quite sure what you exactly wish to accomplish, but maybe you could use the grep command to filter out the words you don't want, creating new files which then you can diff so you can obtain the result you want.

I hope that helps.

Good luck.
 
Old 03-25-2009, 06:30 AM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Looking at the man page, I'd say the -I or '--ignore-matching-lines' options look promising.. maybe --suppress-common-lines
 
Old 03-25-2009, 05:00 PM   #4
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 167Reputation: 167
Quote:
Originally Posted by noir911 View Post
I have one file with



another file with


Is there any way to tell diff to ignore "test" since it appears in both the files and only show "NOTtest" as the diff result since it's not on the other file?
As far as I know, diff will not do this procedure.

grep -v will remove lines... you could do something like:

for i in `cat file2`; do cat file1 | grep -v $i; done

which will result in the correct results, but i suspect only because your example is overly simplified. You could also do this fairly easily in perl in a much more robust way.

heck, even grep -v `cat file2` file1 should return the results you want for that particular example.

Last edited by rweaver; 03-25-2009 at 05:03 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
is it possible to diff ps files? markhod Linux - General 8 09-05-2005 12:17 AM
Using diff for comparing 2 files beep Programming 5 01-21-2005 12:51 PM
Diff compare 2 files DavidTempler Linux - Newbie 2 11-01-2004 10:00 AM
diff for binary files? thorax Linux - Software 2 07-17-2004 02:15 PM
.diff files? jtsai256 Linux - Newbie 1 09-28-2003 02:24 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 05:45 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration