Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 27th, 2005, 3:32 PM   #1
gwilliam
Newbie
 
Join Date: May 2005
Location: swansea wales uk
Posts: 2
Rep Power: 0 gwilliam is on a distinguished road
Smile looping in awk

I need awk to work with two files, read a single column from file1, and taking each value, search for that value in file2.

I guess I need perhaps two forms of "while" loops, one within the other, but cannot get anything to work.

Could anyone give me a simple example to build on?

file1 is created by another process and could have 10 or 20 "codes" that I want to search for in file2 at a fixed position e.g. substr($3,5,4).

Heres hoping someone has done this....
gwilliam is offline   Reply With Quote
Old Jun 14th, 2005, 1:31 PM   #2
jim mcnamara
Hobbyist Programmer
 
Join Date: Jun 2005
Location: New Mexico
Posts: 228
Rep Power: 4 jim mcnamara is on a distinguished road
check out the comm utility first. man comm
jim mcnamara is offline   Reply With Quote
Old Jun 17th, 2005, 10:12 AM   #3
gwilliam
Newbie
 
Join Date: May 2005
Location: swansea wales uk
Posts: 2
Rep Power: 0 gwilliam is on a distinguished road
Thanks, but that doesn't do it for me. What I am trying to do is look through a file(file1) and for each entry in the single column found there, go through the second file locating that entry at a set column position, and if found read value in another column.
The exercise is aimed at producing an output which will be an analysis of the values found by reference to the codes.
gwilliam is offline   Reply With Quote
Old Jun 20th, 2005, 9:12 AM   #4
jim mcnamara
Hobbyist Programmer
 
Join Date: Jun 2005
Location: New Mexico
Posts: 228
Rep Power: 4 jim mcnamara is on a distinguished road
This looks for the presence of column starting at 10 ending at 14 and exists anywhere
in file2.
awk ' {print substr($3,5,4)}' file1 > t.sed
grep -f t.sed file2  > final_output
jim mcnamara is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:56 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC