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 for a particular pattern and remove few lines above top and bottom of the patter fed.linuxgossip Shell Programming and Scripting 17 07-25-2008 08:29 AM
grep to show lines only after pattern wannalearn Shell Programming and Scripting 5 10-09-2007 02:44 AM
Search file for pattern and grab some lines before pattern frustrated1 Shell Programming and Scripting 2 12-22-2005 03:41 PM
Help required regarding Extracting lines from a file google_ever Shell Programming and Scripting 1 10-12-2005 07:02 AM
grep - to exclude lines beginning with pattern frustrated1 Shell Programming and Scripting 2 08-29-2005 07:18 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-31-2008
cvvsnm cvvsnm is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 5
grep required pattern and next 2 or 3 lines

dear ones

pl.kindly help me 1) how to print(grep) required pattern and following 2 or 3 lines. 2) grep required pattern(to print)+above 2 lines+below 2 or 3 lines.from a report file.

ex:
we have some report file
kf askfjsk fksaj fk skf sjfksjd kff sjfkjs kf jskdjfklsd jfklsdf sdkfjsd fsd
jkfsdja fkjsdklf jsdklfj klsdj fklsd jkfjsdkfj ksd jfksdjf 456015
jf sakjlf ksld flksdjklfj sakl jfklsdajklfj sdalfjsdj fksldjfls djfkl


i want to print 456015 and next 1 or 2 lines in some cases. and 456015 + above one line +below 1 or 2 lines.
  #2 (permalink)  
Old 02-01-2008
Yogesh Sawant's Avatar
Yogesh Sawant Yogesh Sawant is offline Forum Staff  
Part Time Moderator and Full Time Dad
  
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 1,086
print 456015 and next one line:
Code:
sed -n '/456015/ {p; n; p;}' file
print 456015 and next two lines:
Code:
sed -n '/456015/ {p; n; p; n; p;}' file
  #3 (permalink)  
Old 02-01-2008
sandeepspecial sandeepspecial is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 2
this also

can u say how to print the line above that search string?
  #4 (permalink)  
Old 02-01-2008
ennstate ennstate is offline
Registered User
  
 

Join Date: Mar 2007
Location: Chennai
Posts: 222
Priting the lines before pattern

The forum has the answer,please check
Pattern matching in file and then display 10 lines above every time

Thanks
Nagarajan G
Sponsored Links
Closed Thread

Bookmarks

Tags
sed

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 10:11 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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