The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 03-11-2009
learning_linux learning_linux is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 2
retrieve lines using sed, grep or awk

Hi,

I'm looking for a command to retrieve a block of lines using sed or grep, probably awk if that can do the job.

In below example,
By searching for words "Third line2" i'm expecting to retrieve the full block starting with 'BEGIN' and ending with 'END' of the search.

Example:

BEGIN
Second line
Third line1
Fourth line
END
BEGIN
Second line
Third line2
Fourth line
END
BEGIN
Second line
Third line3
Fourth line
END

Output Expecting:

BEGIN
Second line
Third line2
Fourth line
END

Note: Block line size can vary & each block can have different line sizes from one other.

Thank you

Last edited by learning_linux; 03-31-2009 at 01:45 AM..