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
find and replace command in one line using one command vasikaran UNIX for Dummies Questions & Answers 10 08-20-2008 07:40 AM
How to replace one line with three in sed ch0sen Shell Programming and Scripting 6 03-05-2008 08:08 AM
Need to replace the first word of a line if it occurs again in the next line(shell) geeko Shell Programming and Scripting 1 09-25-2007 07:15 AM
sed - Replace Line which contains the Pattern match with a new line kousikan Shell Programming and Scripting 2 03-24-2007 03:24 AM
find a shell and replace the line jvellon UNIX for Advanced & Expert Users 1 06-13-2006 05:44 PM

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

Join Date: May 2008
Posts: 9
Stumble this Post!
Find and replace some line

Hi all

I have a file which has n no. of lines. I want to find string called "John"

and add 5 lines below the string. Help me to do it using script?
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-22-2008
Registered User
 

Join Date: Apr 2008
Location: Bangalore
Posts: 120
Stumble this Post!
Hi

awk 'BEGIN{OFS="\n"}
$0 ~ /john/{t=1;}
t==1{print;print "line1","line2","line3",line4","line5";t=0;next}1' filename



Thanks
Penchal
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 05:26 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