Article View: comp.unix.misc
Article #2017Re: Operate on two files at the same time in awk
From: Antonio Vasconcelos
Date: Wed, 06 Oct 1993 22:16
Date: Wed, 06 Oct 1993 22:16
42 lines
2054 bytes
2054 bytes
bvaughan@sheps.Princeton.EDU (Barbara Vaughan) writes:
: for (i = 1; i <= 51; i++){
: getline state[i] < "states"
: }
: }
: { place = $1
: country = place
: for (ii = 1; ii <= 51; ii++){
: if (place == state[ii]){
: country = "United States"
: break
: }
: }
: }
:
:
: I hope this helps. I don't think there's any better way to do it with awk.
But why one should use awk on this?
#!/bin/sh
cat file1 | awk '{print $1}' >x1
cat file2 | awk '{print $1}' >x2
for ff in `cat x1`
do
grep $ff x2 >/dev/null
if [ $? -eq 0 ]
then
echo "HIT $ff"
fi
done
The disk cache should take care of the repetitive access to x2, the
use of awk on the first 2 lines is optional, of course, one could use
cut or another tool to slice the file.
--
| Regards, |
|-------------------------------------------------------------------|
| Antonio Vasconcelos at The Lisbon $tock Exchange - vasco@bvl.pt |
| "I DO *NOT* SPEAK FOR BVL" * NeXTmail * root@bvl.pt |
`-_________________________________________________________________-'
So Long, and Thanks for all the fish.
Technical Details
Message-ID:
<1993Oct6.221646.3864@bvl.pt>Path:
arc1-ca.pugleaf.net!gmd.de!newsserver.jvnc.net!howland.reston.ans.net!europa.eng.gtefsd.com!uunet!mcsun!news.inesc.pt!dec4pt.puug.pt!bvl!vascoReferences:
<1993Oct1.204112.6554@Princeton.EDU>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f8c9b,be6d506f16d4e9f8 X-Google-Attributes: gidf8c9b,public X-Google-Thread: f72b0,be6d506f16d4e9f8 X-Google-Attributes: gidf72b0,public X-Google-Thread: 14b500,be6d506f16d4e9f8 X-Google-Attributes: gid14b500,public X-Google-ArrivalTime: 1993-10-07 02:24:12 PST Newsgroups: comp.unix.misc,comp.unix.questions,bnr.unix Path: arc1-ca.pugleaf.net!gmd.de!newsserver.jvnc.net!howland.reston.ans.net!europa.eng.gtefsd.com!uunet!mcsun!news.inesc.pt!dec4pt.puug.pt!bvl!vasco From: vasco@bvl.pt (Antonio Vasconcelos) Subject: Re: Operate on two files at the same time in awk Message-ID: <1993Oct6.221646.3864@bvl.pt> Organization: Bolsa de Valores de Lisboa X-Newsreader: Tin 1.1 PL4 References: <1993Oct1.204112.6554@Princeton.EDU> Date: Wed, 6 Oct 1993 22:16:46 GMT Lines: 42