The UNIX and Linux Forums  

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



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 01-27-2007
fredao fredao is offline
Registered User
 

Join Date: Dec 2006
Posts: 58
compare two files

I have file1 and file2:

file1:

11 xxx kksd ...
22 kkk kdsglg...
33 sss kdfjdksa...
44 kdsf dskjfkas ...
hh kdkf kdkkd..
jg dkf dfkdk ...
...

file2:

jg
22
hh
...

I need to check each line of file1. if the field one is in file2, I will keep it; if not, the whole line will be discarded. The result file will be:

jg dkf dfkdk ...
22 kkk kdsglg...
hh kdkf kdkkd..
...

please tell me how I can do this, thanks!
Reply With Quote
Forum Sponsor