LINUX.IE, website of the Irish Linux Users' Group
Tux rules!

   
Home
New Users
Articles
Download
Projects
Community
Vendors

  Print Version
Email to...
 
Archives:


planetILUG

Recent News

News Archive


Join the
ILUG
on FaceBook


Join the
ILUG
on LinkedIn


Join the
ILUG SETI
Group



















 
 :: Mailing Lists

[ILUG] text flow tools

[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
Read this without the formatting.
                                                                                                    

 

Hosted by HEAnet


Maintained by the ILUG website team. The aim of Linux.ie is to support and help commercial and private users of Linux in Ireland. You can display ILUG news in your own webpages, read backend information to find out how. Networking services kindly provided by HEAnet, server kindly donated by Dell. Linux is a trademark of Linus Torvalds, used with permission. No penguins were harmed in the production or maintenance of this highly praised website. Looking for the Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!
RSS Version
Powered by Dell