The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-04-2009
cgkmal cgkmal is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 47
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
  #2 (permalink)  
Old 04-04-2009
dennis.jacob dennis.jacob is offline Forum Advisor  
dj - the student
  
 

Join Date: Feb 2007
Location: Singapore/Bangalore/Cochin
Posts: 610
Try this approch:

Quote:
grep -f File_1 File_2
  #3 (permalink)  
Old 04-04-2009
cgkmal cgkmal is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 47
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,
  #4 (permalink)  
Old 04-04-2009
siquadri siquadri is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 44
This should work

Quote:
Originally Posted by cgkmal View Post
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 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

  #5 (permalink)  
Old 04-04-2009
cgkmal cgkmal is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 47
Exactlyyy!!!! siquadri, it works perfect.

Many thanks
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:10 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0