![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | 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. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| grep -f file1 file2 | vijay_0209 | Shell Programming and Scripting | 7 | 03-05-2009 05:48 AM |
| Awk Compare File1 File2 on f2 | RacerX | Shell Programming and Scripting | 4 | 10-27-2008 09:50 AM |
| parsing file2 with input from file1 | forumsgr | Shell Programming and Scripting | 1 | 07-16-2008 07:09 AM |
| match value from file1 in file2 | myguess21 | Shell Programming and Scripting | 2 | 02-21-2008 11:39 AM |
| Awk Compare f1,f2,f3 of File1 with f1 of File2 | RacerX | Shell Programming and Scripting | 6 | 11-09-2007 01:34 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Find numbers from File1 within File2
Hi all, Please your help with this. I have 2 files, File_1-->contains a column of N numbers File_2-->contains many lines with other info and numbers from File_1 within it. I would like to get from File_2 all the lines containing within the same line each of N numbers from File_1 and "DATA=B". I know how to do it for one number with the command: Code:
awk '/97782397979/&&/DATA=1/' File_2 result for this line(viewing below example of File_1 and File_2) Code:
97782397979,RECEIPT=3,DATA=1,MONTH=5 but I canīt do it for all numbers within File_1, I couldnīt get a loop for this yet. Code:
File_1 97782397979 97782397980 97782397981 97782397982 97782397983 97782397984 97782397985 . . . File_2 97782397979,RECEIPT=1,DATA=2,MONTH=1 97782397979,RECEIPT=2,DATA=3,MONTH=2 97782397979,RECEIPT=3,DATA=1,MONTH=5 97782397980,RECEIPT=1,DATA=2,MONTH=1 97782397980,RECEIPT=2,DATA=3,MONTH=2 97782397980,RECEIPT=3,DATA=1,MONTH=7 97782397981,RECEIPT=1,DATA=2,MONTH=1 97782397981,RECEIPT=2,DATA=3,MONTH=2 97782397981,RECEIPT=3,DATA=1,MONTH=5 Thanks in advance for any help. Best regards |
|
||||
|
Hi dennis, This could be part of solution wanted, Iīve tryed but Iīm not sure why doesnīt work. Anything appears in display after several minutes. File_1 is 20MB, File_2 is 178MB size. Maybe someone can modify the line Code:
awk '/97782397979/&&/DATA=1/' File_2 but with a loop that takes each line of File_1 like pattern instead of "97782397979" that works for one event only. Something like Code:
Put in an array File_1 for(i=1,i<=lastline,i++) awk '/line[i]/&&/DATA=1/' File_2 I confuse how to finish this Thanks again, |
|
||||
|
This should work
Quote:
This works Code:
nawk -F"," 'FILENAME="File_1" {arr[$0]=$0} FILENAME="File_2" {if (arr[$1]&& $3 ~/DATA=1/) {print $0}}' File_1 File_2
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|