[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AWK, deleting and comparing lines

From: John Cowan
Subject: Re: AWK, deleting and comparing lines
Date: Mon, 26 Oct 2009 13:36:18 -0400
User-agent: Mutt/1.5.13 (2006-08-11)

David Scherrer scripsit:

> I would like to use AWK to delete lines of a file that have a "C" in
> their first field as well as the closest foregoing line containing a "T"
> in the first field. When there are 2,3,4,... "C"-lines after each other
> I would also like to delete the closest 2,3,4,... foregoing "T"-lines.
> Additionally it would be great if I could compare the "C" and the "T"
> line and condition deletion upon on the comparison result. E.g. delete
> the closest forgoing "T"-line above with fields 4 and 6 the same as the
> "C"-line.

This involves deleting lines you have already processed.  Your only
hope is to slurp the whole file into an array of lines indexed by line
number and do all the work in the END block, printing out the array
as the last thing.  This may make your awk implementation blow up,
depending on what implementation it is and what computer you are using.

Perl makes this sort of thing rather easier.

John Cowan           http://www.ccil.org/~cowan            address@hidden
One of the oil men in heaven started a rumor of a gusher down in hell.  All
the other oil men left in a hurry for hell.  As he gets to thinking about
the rumor he had started he says to himself there might be something in
it after all.  So he leaves for hell in a hurry.    --Carl Sandburg

reply via email to

[Prev in Thread] Current Thread [Next in Thread]