Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

scripting -- list until next blank line

Status
Not open for further replies.

fudge

Technical User
Jun 7, 2001
9
GB
Hi,

I'm, looking for an instruction that will allow me to search a file, grab a heading and list everything under the heading until the next blank line and/or enable me to pipe into another command.
 
Hi,

cat file | grep -p <string> | <command>

This greps every paragraph starting with the string till next blank line,and pipes into a <command>. &quot;Long live king Moshiach !&quot;
 
If you want to use awk (I did):

awk 'BEGIN { FS = &quot;\n&quot;; RS = &quot;^\n&quot; } $0 ~ pattern { print $0 }' file

Maybe awk is overkill for this, and someone may want to verify that &quot;^\n&quot; will match a blank line. Notice also that this prints the entire &quot;paragraph&quot; but you can print selective lines by changing &quot;print $0&quot; to some other record number.

This avoids a useless use of cat, as well.
 
I verified... to match a blank line as the record separator:

RS=&quot;&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top