Article View: comp.unix.misc
Article #2011Re: Operate on two files at the same time in awk
From: Chris Lewis
Date: Thu, 30 Sep 1993 23:51
Date: Thu, 30 Sep 1993 23:51
33 lines
1776 bytes
1776 bytes
In article <1993Sep30.171928.6462@bmerh85.bnr.ca>,
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.
I take it that file1 is multiple lines?
Something like this (untested) works as a brute force approach:
echo "FILE2START" | cat file1 - file2 | awk '
/FILE2START/ { infile2 = 1
next
}
{
if (infile2) {
for (i in tokens)
if ($0 ~ i)
next
print $0
} else
tokens[$1] = 1
}'
Hopefully file1 isn't too large.
--
Every once in a while I write something that someone might use
in a signature. So I go back and make it real spiffy. No luck.
Then some guy goes and uses *that* dog. Argh!
Technical Details
Message-ID:
<1993Sep30.235144.20183@bcars6a8.bnr.ca>Path:
arc1-ca.pugleaf.net!gmd.de!newsserver.jvnc.net!yale.edu!spool.mu.edu!torn!nott!bnrgate!bcars6a8!clewisReferences:
<1993Sep30.171928.6462@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: 14b500,be6d506f16d4e9f8 X-Google-Attributes: gid14b500,public X-Google-Thread: f72b0,be6d506f16d4e9f8 X-Google-Attributes: gidf72b0,public X-Google-ArrivalTime: 1993-09-30 17:20:41 PST Newsgroups: comp.unix.misc,comp.unix.questions,bnr.unix Path: arc1-ca.pugleaf.net!gmd.de!newsserver.jvnc.net!yale.edu!spool.mu.edu!torn!nott!bnrgate!bcars6a8!clewis From: clewis@bcarh2ec.bnr.ca (Chris Lewis) Subject: Re: Operate on two files at the same time in awk Message-ID: <1993Sep30.235144.20183@bcars6a8.bnr.ca> Sender: usenet@bcars6a8.bnr.ca (Use Net) Nntp-Posting-Host: bcarh2ec Organization: Bell Northern Research Ltd, Ottawa, Canada References: <1993Sep30.171928.6462@bmerh85.bnr.ca> Date: Thu, 30 Sep 1993 23:51:44 GMT Lines: 33