The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Grep and delete lines except the lines with strings vj8436 Shell Programming and Scripting 14 04-17-2009 11:25 AM
retrieve lines that match a pattern fadista UNIX for Dummies Questions & Answers 2 12-10-2008 04:40 AM
retrieve lines from file which fall under the given date range Sharmila_P Shell Programming and Scripting 5 07-31-2008 08:30 AM
grep and fetching lines after grep arghya_owen Shell Programming and Scripting 2 07-16-2008 07:25 AM
retrieve text after grep frustrated1 UNIX for Dummies Questions & Answers 2 12-16-2006 11:42 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #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 12:45 AM..
  #2 (permalink)  
Old 03-11-2009
Whiteboard's Avatar
Whiteboard Whiteboard is offline
Registered User
  
 

Join Date: Feb 2009
Location: @........
Posts: 111
Can you post your desired output...
  #3 (permalink)  
Old 03-25-2009
learning_linux learning_linux is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 2
Whiteboard,
have updated the expected output. Thanks
  #4 (permalink)  
Old 03-25-2009
Whiteboard's Avatar
Whiteboard Whiteboard is offline
Registered User
  
 

Join Date: Feb 2009
Location: @........
Posts: 111
Code:
$ grep -B 2 -A 2 "Third line2" filename
BEGIN
Second line
Third line2
Fourth line
END
Sponsored Links
Closed Thread

Bookmarks

Tags
grep or

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 09:09 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0