Article View: comp.unix.shell
Article #1645How to get AWK to output 2 fields at once
From: Bill Irwin
Date: Sun, 28 Oct 1990 19:20
Date: Sun, 28 Oct 1990 19:20
24 lines
1485 bytes
1485 bytes
I have what initially seemed to be a simple requirement: get the first
two fields from each line in file_1, and use them as a search pattern for
GREP to extract matching lines in file_2. Sounds simple doesn't it? Not
for someone with very limited knowledge of AWK! The first pass at this
was:
for x in `cat file_1 | awk '{ print $1 " " $2 }'`
do
grep "$x" file_2
done
Of course, the GREP routine executed with x having the value of the first
field of the first line of file_1, then with the value of the second
field of the first line of file_1, then the first field of the second
line, .....
Is there a way to get AWK to output "field_1 field_2" as the value of x,
so that this can be used as the search pattern for GREP, rather than
"field_1" "field_2" "field_1" "field_2"?
--
Bill Irwin - The Westrheim Group - Vancouver, BC, Canada
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
uunet!van-bc!twg!bill (604) 431-9600 (voice) | UNIX Systems
bill@twg.bc.ca (604) 430-4329 (fax) | Integration
Technical Details
Message-ID:
<297@twg.bc.ca>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!nih-csl!lhc!ncifcrf!haven!uflorida!rex!wuarchive!mit-eddie!uw-beaver!ubc-cs!van-bc!twg!billShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!nih-csl!lhc!ncifcrf!haven!uflorida!rex!wuarchive!mit-eddie!uw-beaver!ubc-cs!van-bc!twg!bill From: bill@twg.bc.ca (Bill Irwin) Newsgroups: comp.unix.shell Subject: How to get AWK to output 2 fields at once Message-ID: <297@twg.bc.ca> Date: 28 Oct 90 19:20:04 GMT Organization: The Westrheim Group, Vancouver, B.C., Canada Lines: 24