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, replace string in file1 with string from (lookup table) file2? gstuart Shell Programming and Scripting 9 06-08-2009 07:11 AM
search excat string in another string (grep "fails") bora99 UNIX for Dummies Questions & Answers 0 06-05-2008 07: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 03:21 PM
Perl: Search for string on line then search and replace text Crypto Shell Programming and Scripting 4 01-04-2008 10:24 AM
grep: RE error 41: No remembered search string. fkaba81 Shell Programming and Scripting 2 06-22-2006 03:23 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 03-12-2008
raga raga is offline
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.
  #2 (permalink)  
Old 03-12-2008
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,930
grep -A 10 "search string" file
  #3 (permalink)  
Old 03-12-2008
raga raga is offline
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.
  #4 (permalink)  
Old 03-12-2008
sanjaypraj sanjaypraj is offline
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.
  #5 (permalink)  
Old 03-12-2008
Tytalus's Avatar
Tytalus Tytalus is offline Forum Advisor  
echo {1..9}^2\;|bc
  
 

Join Date: Jun 2003
Location: Scotland
Posts: 431
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
  #6 (permalink)  
Old 03-12-2008
radoulov's Avatar
radoulov radoulov is online now Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,881
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
  #7 (permalink)  
Old 03-12-2008
raga raga is offline
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.
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 07:50 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