🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.misc
Article #2013

Re: Operate on two files at the same time in awk

#2013
From: Vilok Kusumakar
Date: Fri, 01 Oct 1993 18:10
24 lines
1771 bytes
>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 Kusumakar                    OSI Protocols for tomorrow......
vilok@bnr.ca                       Bell-Northern Research, Ltd.
Phone: (613) 763-2273              P.O. Box 3511, Station C 
Fax:   (613) 765-4777              Ottawa, Ontario, K1Y 4H7
Technical Details
Message-ID: <1993Oct1.181038.2707@bmerh85.bnr.ca>
Path: arc1-ca.pugleaf.net!gmd.de!newsserver.jvnc.net!udel!gatech!usenet.ins.cwru.edu!magnus.acs.ohio-state.edu!math.ohio-state.edu!cs.utexas.edu!uunet!pipex!bnr.co.uk!corpgate!nmerh207!bmerh85!bmerh322!vilok
References: <1993Sep30.171928.6462@bmerh85.bnr.ca> <1993Oct1.154830.29504@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 11:55:08 PST
Newsgroups: comp.unix.misc,comp.unix.questions,bnr.unix
Path: arc1-ca.pugleaf.net!gmd.de!newsserver.jvnc.net!udel!gatech!usenet.ins.cwru.edu!magnus.acs.ohio-state.edu!math.ohio-state.edu!cs.utexas.edu!uunet!pipex!bnr.co.uk!corpgate!nmerh207!bmerh85!bmerh322!vilok
From: vilok@bmerh322.bnr.ca (Vilok Kusumakar)
Subject: Re: Operate on two files at the same time in awk
Message-ID: <1993Oct1.181038.2707@bmerh85.bnr.ca>
Sender: news@bmerh85.bnr.ca (Usenet News)
Reply-To: vilok@bnr.ca
Organization: Bell-Northern Research
References: <1993Sep30.171928.6462@bmerh85.bnr.ca> <1993Oct1.154830.29504@bmerh85.bnr.ca>
Date: Fri, 1 Oct 93 18:10:38 GMT
Lines: 24