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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
print a line containing word in a column using grep useless79 Shell Programming and Scripting 2 11-23-2007 12:32 AM
grep the line only if next line matches pbsrinivas Shell Programming and Scripting 11 07-10-2007 05:51 AM
Printing the following line that matches an string jgarcia Shell Programming and Scripting 7 05-09-2007 10:31 PM
Can a shell script pull the first word (or nth word) off each line of a text file? tricky Shell Programming and Scripting 5 08-17-2006 03:29 AM
Select matches between line number and end of file? Jerrad Shell Programming and Scripting 4 05-24-2006 04:50 AM

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

Join Date: Jun 2008
Posts: 12
Post print next line if matches a particular word..need help

Hi
i need a help for making a script whch can print next line if it matches a particular word
like file1 have
ename Mohan
eid 2008
ename Shyam
eid 345

if scipt got Mohan it will print next line (eid 2008)

pls help me .......
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 06-12-2008
Part Time Moderator and Full Time Dad
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 758
try this:
Code:
sed -n -e '/Mohan/ {n; p;}' filename
Reply With Quote
  #3 (permalink)  
Old 06-12-2008
Registered User
 

Join Date: Jun 2008
Posts: 12
Hi

Thanks for ur reply but have little bit doubt

if i have file
ename Mohan
ename2 Mohan
eid 2008
ename Shyam
eid 345

and i will give sed -n -e '/Mohan/ {n; p;}' filename
it wiil give output
ename2 Mohan

here when command finds Mohan it is prinitng next line ename2 Mohan but it should also print eid 2008 as file is also having line ename2 Mohan
Reply With Quote
Google UNIX.COM
Reply

Tags
sed

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:14 AM.


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

Content Relevant URLs by vBSEO 3.2.0