The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
file comparison...help needed. er_ashu UNIX for Dummies Questions & Answers 4 05-15-2008 06:37 PM
Comparison Unix and Windows file sysytem localp UNIX for Dummies Questions & Answers 1 04-11-2008 01:02 AM
Output format - comparison with I/p file velappangs Shell Programming and Scripting 1 04-03-2008 03:31 AM
file comparison script tiger99 Shell Programming and Scripting 1 01-30-2008 07:47 AM
File Time Comparison Question pc9456 UNIX for Advanced & Expert Users 2 07-23-2003 12:05 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #8  
Old 01-02-2008
rikxik's Avatar
Registered User
 

Join Date: Dec 2007
Posts: 105
Do we have to loop?

Code:
$ cat f1
11111122222222333333aaaaaaaaaabbbbbbbbbccccccccdddddd
91111122222222333333aaaaaaaaaabbbbbbbbbccccccccdddddd
81111122222222333333aaaaaaaaaabbbbbbbbbccccccccdddddd
$
$ cat f2
11111122222222333333aaaaaaaaaabbbbbbbbbccccccccddeddd
11111122222222333333aaaaaaaaaabbbbbbbbbccccccccdddddd
11111122222222333333aaaaaaaaaabbbbbbbbbccccccccddeddd
91111122222222333333aaaaaaaaaabbbbbbbbbccccccccdddddd
$
$ diff f1 f2 |grep "<" |cut -d"<" -f2 |cut -c2-
81111122222222333333aaaaaaaaaabbbbbbbbbccccccccdddddd
HTH
Reply With Quote
Forum Sponsor
  #9  
Old 01-02-2008
Registered User
 

Join Date: Jan 2008
Posts: 5
I'd probably use diff too...

If the lines in the files are similar to the lines you put in your first post, meaning there are no spaces on the lines, you could:

Code:
#!/bin/sh
for k in `cat file1`
do
  grep -m 1 $k file2 > /dev/null
  if [ $? -eq 1 ]; then echo $k; fi 
done
the -m1 will cause grep to exit after the first match is found. If no match is found grep will exit with status 1, you can use that to determine if the line exists in file 2 or not. Keep in mind, that "for k in `cat`" stuff will break if you have spaces in the lines in the file.
Reply With Quote
  #10  
Old 01-03-2008
Registered User
 

Join Date: Nov 2007
Posts: 85
You can use grep -v -f

grep -v -f file1 file2

This will give you all the lines in file2 which are not in file1
Reply With Quote
  #11  
Old 01-03-2008
Registered User
 

Join Date: Dec 2007
Posts: 8
This is excellant stuff, this is exactly what I wanted. Thank you so much.
Reply With Quote
  #12  
Old 01-04-2008
Registered User
 

Join Date: Dec 2007
Posts: 8
Guess I got excited too early.
It worked fine for small files, but when I tried on large files (200+MB), it ran for 3 hours and still was running and I had to kill.
Appreciate for any other alternate tips considering the size of the files also.
Reply With Quote
  #13  
Old 01-04-2008
Registered User
 

Join Date: Jan 2008
Posts: 5
Which one were you running?
Reply With Quote
  #14  
Old 01-05-2008
Registered User
 

Join Date: Dec 2007
Posts: 8
grep -v -f file1 file2
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
linux

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 07:30 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0