The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

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 09:29 AM
grep required pattern and next 2 or 3 lines cvvsnm UNIX for Dummies Questions & Answers 3 02-01-2008 05:20 AM
Search file for pattern and grab some lines before pattern frustrated1 Shell Programming and Scripting 2 12-22-2005 03:41 PM
grep - to exclude lines beginning with pattern frustrated1 Shell Programming and Scripting 2 08-29-2005 08:18 AM
Need ls to show number of lines in each file GMMike UNIX for Dummies Questions & Answers 1 11-19-2004 05:53 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-12-2007
wannalearn wannalearn is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 33
grep to show lines only after pattern

When i grep for a pattern the search results comes up with matching lines(some before the pattern and some after)...how can i limit the search so that it shows only the lines after the pattern specified
  #2 (permalink)  
Old 06-12-2007
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
Quote:
Originally Posted by wannalearn
When i grep for a pattern the search results comes up with matching lines(some before the pattern and some after)...how can i limit the search so that it shows only the lines after the pattern specified
You must have provided some extra flags for grep. Show us the grep command that you issued. GNU grep talks about
Code:
       -A NUM, --after-context=NUM
              Print NUM lines of trailing context after matching lines.  Places
              a line containing -- between contiguous groups of matches.
       -B NUM, --before-context=NUM
              Print NUM lines of leading context before matching lines.  Places
              a line containing -- between contiguous groups of matches.
Surely you must be have provided both the flags.
  #3 (permalink)  
Old 06-12-2007
wannalearn wannalearn is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 33
hmm..

This wont help..
Print NUM lines of trailing context after matching lines..


Instead of lines I need pattern


Eg: Say i search for a pattern abc...the result i get is hdhd fhfhfh abc hdh jdhf

I want the result to be hdh jdhf

I went through the man page for grep and couldnt find any option which would help me accomplish the above result :-(
  #4 (permalink)  
Old 06-12-2007
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
You might want to look into the -E flag to see if it helps you. Off the top of my head, I can say, you could use sed.

Code:
sed -n -e "s/.*abc \(hdh jdhf\)/\1/p" input.txt
See if it helps. You might want to tweak things a bit.
  #5 (permalink)  
Old 06-12-2007
wannalearn wannalearn is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 33
nope

-E doesnt help too...

I came around with a workaround using awk -F ! :-)
  #6 (permalink)  
Old 10-09-2007
royalibrahim royalibrahim is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 86
Hi wannalearn, I need that "awk" script that you used to print 'n' no of lines below the matching pattern including that line also.

grep -A<n> "pattern" <file> --> will do the job, though I need an awk script for this. Please provide me.
Closed Thread

Bookmarks

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 01:17 AM.


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