Article View: comp.unix.misc
Article #2014Re: Operate on two files at the same time in awk
From: Drago Goricanec
Date: Fri, 01 Oct 1993 19:49
Date: Fri, 01 Oct 1993 19:49
38 lines
2355 bytes
2355 bytes
In article <1993Oct1.181038.2707@bmerh85.bnr.ca>,
Vilok Kusumakar <vilok@bnr.ca> wrote:
|> >Vilok Kusumakar <vilok@bnr.ca> wrote:
|> >>I have a problem for awk experts:
|> >>
|> >>I have two text files file1 and file2.
|> >>
|> >>I want to look for presence of string at $1(1st column) in file1 in
|> >>file2. And print out all the lines in file1 whose $1 is not present
|> >>in any line in file2.
|>
|> Thanks for all the solutions. I did it as follows:
|>
|> sort file1 > sorted1
|> sort file2 > sorted2
|> awk '{
|> KEY1=$1; LINE1=$0;
|> while (KEY2 < KEY1 && getline <"sorted2") KEY2=$1;
|> if (KEY2 != KEY1) print LINE1;
|> }' sorted1
Vilok, I know you prefer a solution that reduces the amount you have to
type. Try the following:
cut -d\ -f1 file2 >keys; grep -v -f keys file1
^
Need to tell cut, that space is your delimiter
The -f option used to be available on egrep, but I checked the man page,
and it seems the three (grep, fgrep, egrep) have been consolidated to one
on our machines (HP-UX 8.0)
cheers,
Drago
--
Drago Goricanec, +1 613 763-8957, Internet: dragog@bnr.ca
Communications Systems, Software Development (OSI Protocols)
Opinions expressed are not necessarily those of BNR.
Technical Details
Message-ID:
<1993Oct1.194920.5030@bmerh85.bnr.ca>Path:
arc1-ca.pugleaf.net!gmd.de!newsserver.jvnc.net!yale.edu!nigel.msen.com!sdd.hp.com!vixen.cso.uiuc.edu!uwm.edu!math.ohio-state.edu!cs.utexas.edu!TAMUTS.TAMU.EDU!news.utdallas.edu!corpgate!nmerh207!bmerh85!bmerh92!dragogReferences:
<1993Sep30.171928.6462@bmerh85.bnr.ca> <1993Oct1.154830.29504@bmerh85.bnr.ca> <1993Oct1.181038.2707@bmerh85.bnr.ca>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-01 13:33:26 PST Newsgroups: comp.unix.misc,comp.unix.questions,bnr.unix Path: arc1-ca.pugleaf.net!gmd.de!newsserver.jvnc.net!yale.edu!nigel.msen.com!sdd.hp.com!vixen.cso.uiuc.edu!uwm.edu!math.ohio-state.edu!cs.utexas.edu!TAMUTS.TAMU.EDU!news.utdallas.edu!corpgate!nmerh207!bmerh85!bmerh92!dragog From: dragog@bmerh92.bnr.ca (Drago Goricanec) Subject: Re: Operate on two files at the same time in awk Message-ID: <1993Oct1.194920.5030@bmerh85.bnr.ca> Sender: news@bmerh85.bnr.ca (Usenet News) Reply-To: dragog@bmerh85 (Drago Goricanec) Organization: Bell-Northern Research Ltd., Ottawa, Ontario, Canada References: <1993Sep30.171928.6462@bmerh85.bnr.ca> <1993Oct1.154830.29504@bmerh85.bnr.ca> <1993Oct1.181038.2707@bmerh85.bnr.ca> Date: Fri, 1 Oct 93 19:49:20 GMT Lines: 38