[ILUG] text flow tools
Paul Jakma
paul at clubi.ie
Wed Jul 27 23:35:19 IST 2005
On Wed, 27 Jul 2005, Paul Biggar wrote:
> Folks,
>
> grep can find two words one after the other by doing 'grep "word1
> word2"'. Does anybody know a way of making this return a case where
> word1 is at the end of one line, and word2 is at the start of the
> next.
Using GNU AWK, something vaguely like (untested):
BEGIN {
latch = 0;
}
/word1$/ {
line1 = $0;
latch = 1;
getline;
}
latch == 1 {
if ($1 == "word1")
print line1,$0;
latch = 0;
}
You can of course replace all \n's in the above with spaces and
enclose it with ' to run it as a gawk commandline script. The BEGIN
section is unneccesary, gawk initialises variables to 0 on first use,
but it's good practice to explicitely initialise global's in the
first BEGIN section, prior to all usage, ime.
regards,
--
Paul Jakma paul at clubi.ie paul at jakma.org Key ID: 64A2FF6A
Fortune:
The difference between reality and unreality is that reality has so
little to recommend it.
-- Allan Sherman
More information about the ILUG
mailing list