The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 03-12-2009
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,807
Use associative arrays in awk. This finds names that occur in both files. It is case-sensitive and sensitive to extra spaces - in other words an exact match

Code:
awl '{ if(FILENAME=="file1") (arr[$0]++}
        if(FILENAME=="file2") {if($0 in arr) {print $0)} }
      }'  file1 file2

Nested loops like you describe take far too long. This is about as godd as it gets.