![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Finding Names in multiple files | Rally_Point | UNIX for Dummies Questions & Answers | 3 | 02-23-2009 08:36 PM |
| Finding missing sequential file names | Julolidine | Shell Programming and Scripting | 2 | 07-02-2008 11:52 PM |
| Finding files with names that have a real number greater then difined. | harmonwood | Shell Programming and Scripting | 2 | 11-09-2007 10:28 AM |
| finding duplicate files by size and finding pattern matching and its count | jerome Sukumar | Shell Programming and Scripting | 2 | 12-01-2006 04:20 AM |
| how to find capital letter names in a file without finding words at start of sentence | kev269 | Shell Programming and Scripting | 1 | 04-10-2006 09:35 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Finding names in multiple files - second attempt
I couldn't find the original thread that I created and since I didn't get a definitive answer, I figured I'd try again. Maybe this time I can describe what I want a little better.
I've got two files, each with thousands of names all separated by new line. I want to know if 'name in file1' also appears anywhere in file 2 then print it out for me (though output isn't the problem). I've thought that maybe there's a way to walk through the first file and with each line then walk through each line in the second file (something like a nested loop statement) and then go from there. I'm just wondering if that will work of if there is a better and EASIER way. Thanks |
|
||||
|
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
|
|
||||
|
Quote:
Something like: Code:
while read name;do grep "$name" file2;done < file1 Code:
while read name;do echo $name:;grep "$name" file2;done < file1 Code:
while read name;do ;grep -q "$name" file2 && echo $name found in file2;done < file1 Best regards /Lakris |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|