🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.misc
Article #2016

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

#2016
From: Randal L. Schwartz
Date: Tue, 05 Oct 1993 19:50
27 lines
1917 bytes
>>>>> In article <1993Sep30.171928.6462@bmerh85.bnr.ca>, vilok@bmerh322.bnr.ca (Vilok Kusumakar) writes:

Vilok> I have a problem for awk experts:
well, I *used* to be an awk expert... :-)

Vilok> I have two text files file1 and file2.

Vilok> I want to look for presence of string at $1(1st column) in file1 in 
Vilok> file2. And print out all the lines in file1 whose $1 is not present 
Vilok> in any line in file2.

#!/usr/bin/perl
($ONE,$TWO) = @ARGV; # name the arguments
open(ONE) || die "no $ONE!";
open(TWO) || die "no $TWO!";
$alltwo = join("",<TWO>);
while (<ONE>) {
	next unless ($oneone) = /^\s*(\S+)/;
	next unless index($alltwo,$oneone);
	print;
}

print "Just another Perl hacker,"
-- 
Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
merlyn@ora.com (semi-permanent) merlyn@agora.rain.com (for newsreading only)
phrase: "Welcome to Portland, Oregon ... home of the California Raisins!"
Technical Details
Message-ID: <MERLYN.93Oct5115036@agora.rain.com>
Path: arc1-ca.pugleaf.net!gmd.de!xlink.net!howland.reston.ans.net!sol.ctr.columbia.edu!news.kei.com!ssd.intel.com!chnews!ornews.intel.com!percy!agora!merlyn
References: <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-10-05 12:56:59 PST
Newsgroups: comp.unix.misc,comp.unix.questions,bnr.unix
Path: arc1-ca.pugleaf.net!gmd.de!xlink.net!howland.reston.ans.net!sol.ctr.columbia.edu!news.kei.com!ssd.intel.com!chnews!ornews.intel.com!percy!agora!merlyn
From: merlyn@ora.com (Randal L. Schwartz)
Subject: Re: Operate on two files at the same time in awk
In-Reply-To: vilok@bmerh322.bnr.ca's message of Thu, 30 Sep 93 17:19:28 GMT
Message-ID: <MERLYN.93Oct5115036@agora.rain.com>
Sender: merlyn@agora.rain.com (Randal L. Schwartz)
Organization: Stonehenge Consulting Services; Portland, Oregon, USA
References: <1993Sep30.171928.6462@bmerh85.bnr.ca>
Date: Tue, 5 Oct 1993 19:50:36 GMT
Lines: 27