|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Need to search string from file 1 in one of columns of file 2
hello all. I would like to kindly ask you, if you could help me out with one problem. I have two files -> for ex. file1 and file2 file1 contains only various numbers file 2 contains multiple columns with various values What i need is to take every single number, one by one, from file 1 and check if this number occurs in column 5 of file 2 - doesnt matter if it occurs for several times file 1 Code:
49000186672011 49000186682011 49000186692011 49000186702011 49000186712011 49000186722011 49000186732011 49000186742011 49000186762011 file 2 Code:
4900017287 2011 WA CO11N 49000186672011 4900017288 2011 WA CO11N 49000186682011 4900017289 2011 WA CO11N 49000186692011 4900017290 2011 WA CO11N 49000186702011 4900017291 2011 WA CO11N 49000186712011 4900017292 2011 WA CO11N 49000186722011 4900017293 2011 WA CO11N 49000186732011 4900017294 2011 WA CO11N 49000186742011 4900017296 2011 WA CO11N 49000186762011 Desired output if matching : Code:
4900017287 2011 WA CO11N 49000186672011 X 4900017288 2011 WA CO11N 49000186682011 X 4900017289 2011 WA CO11N 49000186692011 X 4900017290 2011 WA CO11N 49000186702011 X 4900017291 2011 WA CO11N 49000186712011 X 4900017292 2011 WA CO11N 49000186722011 X 4900017293 2011 WA CO11N 49000186732011 X 4900017294 2011 WA CO11N 49000186742011 X 4900017296 2011 WA CO11N 49000186762011 X Thank you all in advance for any useful hints. I tried already some loops, awk searches but without any desired success. Last edited by Scrutinizer; 12-10-2012 at 03:48 PM.. Reason: code tags |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
thanks ! seems to be working well!
|
|
#4
|
|||
|
|||
|
Code:
awk 'NR==FNR {a[$1];next} $5 in a {print $0,"X"}' file1 file2 |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Search based on 1,2,4,5 columns and remove duplicates in the same file. | onesuri | Shell Programming and Scripting | 2 | 10-25-2010 05:00 AM |
| search string in a file and retrieve 10 lines including string line | sukrish | Shell Programming and Scripting | 8 | 08-19-2010 03:53 PM |
| how can search a String in one text file and replace the whole line in another file | kkraja | UNIX for Dummies Questions & Answers | 6 | 08-06-2008 07:23 AM |
| how to search string and number in one file and check in the other file | knshree | Shell Programming and Scripting | 9 | 08-24-2007 04:29 AM |
| appending string to text file based on search string | malaymaru | Shell Programming and Scripting | 1 | 06-09-2006 08:53 AM |
|
|