The UNIX and Linux Forums  

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
search excat string in another string (grep "fails") bora99 UNIX for Dummies Questions & Answers 0 06-05-2008 03:41 AM
problem with grep on search string in a txt file over multiple files m00 UNIX for Dummies Questions & Answers 2 05-18-2008 11:21 AM
Search, replace string in file1 with string from (lookup table) file2? gstuart Shell Programming and Scripting 2 04-11-2008 11:32 AM
Perl: Search for string on line then search and replace text Crypto Shell Programming and Scripting 4 01-04-2008 06:24 AM
grep: RE error 41: No remembered search string. fkaba81 Shell Programming and Scripting 2 06-21-2006 11:23 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-12-2008
Registered User
 

Join Date: Mar 2008
Posts: 4
grep for a search string

Hi,

I want to grep one file for a search string and get the next 10 lines after the search string.
for eg,in file tnsnames.ora,i have 100 entries.i want to search for one string and get the entry for that db.

please help how to acheive this using awk or sed?

Thanks.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-12-2008
Moderator
 

Join Date: Dec 2003
Location: /dev/florida
Posts: 955
grep -A 10 "search string" file
Reply With Quote
  #3 (permalink)  
Old 03-12-2008
Registered User
 

Join Date: Mar 2008
Posts: 4
hi,
grep -A is not working for HP unix.
$ grep -A 10 "ARMP" tnsnames.ora
grep: illegal option -- A

please let me know is there any other option?
Thanks.
Reply With Quote
  #4 (permalink)  
Old 03-12-2008
Registered User
 

Join Date: Mar 2008
Posts: 7
Will a shell script do for you? I don't know if it can be done using some command.
Reply With Quote
  #5 (permalink)  
Old 03-12-2008
Tytalus's Avatar
Registered User
 

Join Date: Jun 2003
Location: Scotland
Posts: 249
probably an easier way to do this but, this works....

Code:
#  sed -ne '/string/{
n
p
n
p
n
p
n
p
n
p
n
p
n
p
n
p
n
p
n
p
}
' infile
Reply With Quote
  #6 (permalink)  
Old 03-12-2008
radoulov's Avatar
addict
 

Join Date: Jan 2007
Location: Milan, Italy/Varna, Bulgaria
Posts: 1,562
Quote:
Originally Posted by raga View Post
[...]
I want to grep one file for a search string and get the next 10 lines after the search string.
[...]
Code:
awk '/pattern/{c=11}c&&c--' file
Reply With Quote
  #7 (permalink)  
Old 03-12-2008
Registered User
 

Join Date: Mar 2008
Posts: 4
HI,
awk '/pattern/{c=11}c&&c--' file
this actually returned me all the 11 lines from the occurance of the pattern in the file.
But i didnt understand how it is working?can you please explain me.

Thank you.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 12:09 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0