The UNIX and Linux Forums  


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



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Reply
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-01-2009
Registered User
 

Join Date: Jun 2009
Posts: 20
AWK: read values from file1; search for values in file2

I have read another post about this issue and am wondering how to adapt it
to my own, much simpler, issue.

I have a file of user IDs like so:

Code:
333333
321321
546465

...etc

I need to take each number and use it to print records wherein the 5th
field matches the user ID pulled from the first file. Naively, I thought success
was a while loop away.


Code:
while read line;do awk -F'\t' '$5 ~ /line/ {print $0}' line="$line" FULL-RECORDS.txt;done < USER-ID.txt > new.txt

As you can see, the second file contains full records ( tab delimited ) for each user
like so ( sanitized for your pleasure ):

Code:
"CHUCKLES, WARREN P."   04   555 FAKE ADDRESS  (302) 555-5555 545465 120
"CORMORANT, HOPPY P."   04   565 FAKE ADDRESS  (302) 555-5555 545466 120

Advice?

Thanks for reading!

Bubnoff
  #2 (permalink)  
Old 12-01-2009
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,145
It doesn't look like it's the FIFTH field that you need to match - it looks like it's the THIRD field (based on your sample) - you have embedded space(s) in the first field. Try it out and adjust to your likings.

Code:
awk -F'\t' '
  FNR==NR {idsA[$1]; next}
  $3 in idsA
' USER-ID.txt FULL-RECORDS.txt

Bits Awarded / Charged to vgersh99 for this Post
Date User Comment Amount
12-01-2009 Bubnoff N/A 10
  #3 (permalink)  
Old 12-01-2009
Registered User
 

Join Date: Jun 2009
Posts: 20
BRILLIANT ~~

My AWK knowledge has been raised to a new level and my problem was
solved.

Thanks!!!

Bub
Sponsored Links
Reply

Bookmarks

Tags
awk

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 Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Search, replace string in file1 with string from (lookup table) file2? gstuart Shell Programming and Scripting 9 06-08-2009 07:11 AM
Read each word from File1 and search each file in file2 clem2610 Shell Programming and Scripting 8 04-23-2009 09:13 AM
Search values between ranges in File1 within File2 cgkmal Shell Programming and Scripting 4 01-31-2009 06:37 PM
awk/sed search lines in file1 matching columns in file2 floripoint Shell Programming and Scripting 1 12-17-2008 11:36 PM
Korn Shell Script - Read File & Search On Values run_unx_novice Shell Programming and Scripting 2 06-15-2005 08:20 AM



All times are GMT -4. The time now is 01:22 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