The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
insert a line after specific line namishtiwari Shell Programming and Scripting 8 05-21-2008 02:16 PM
how to delete text from line starting pattern1 up to line before pattern2? repudi8or Shell Programming and Scripting 5 04-15-2008 09:25 PM
how to delete line with matching text and line immediately after orahi001 UNIX for Dummies Questions & Answers 6 01-15-2008 12:34 AM
how to insert a line number on every line mopimp UNIX for Dummies Questions & Answers 3 03-25-2006 01:35 PM
Insert a line as the first line into a very huge file shriek UNIX for Advanced & Expert Users 3 03-09-2005 01:22 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-19-2008
RahulJoshi's Avatar
RahulJoshi RahulJoshi is offline
Registered User
  
 

Join Date: Aug 2008
Location: PUNE
Posts: 98
How to insert and delete any line after desire line

like i have file like

abc
123
pqr
bbbb
ttttttttt
t
tttt
------------------
i want to insert "class" after pqr and t lines
please suggest me.
  #2 (permalink)  
Old 10-19-2008
dennis.jacob dennis.jacob is offline Forum Advisor  
dj -------
  
 

Join Date: Feb 2007
Location: Singapore/Bangalore/Cochin
Posts: 560
Try:

Code:
sed -e '/pqr/G' -e '/^t$/G' < filename | sed  's/^$/class/g'
  #3 (permalink)  
Old 10-19-2008
RahulJoshi's Avatar
RahulJoshi RahulJoshi is offline
Registered User
  
 

Join Date: Aug 2008
Location: PUNE
Posts: 98
THANKS FOR REPLY
but it also insert row at last also, and please tell If I want to insert row after 2 rows of desire row
like:
i/p:
pqr
abcv
dddd
33333
--------------
o/p insert "best" after 2 rows of pqr
pqr
abcv
dddd
best
33333
----------------------
  #4 (permalink)  
Old 10-20-2008
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,078
pls try below sed command

Code:
sed -n '/pqr/ !{
p
}
/pqr/ {
p
n
p
n
p
i\
best
}' filename
below is the same with above ( insert line after match)
Code:
sed '/pqr/a\
------------------
/^t$/a\
------------------
' filename
below is the slightly different ( insert line before match line)
Code:
sed '/pqr/i\
------------------
/^t$/i\
------------------
' filename

Last edited by summer_cherry; 10-21-2008 at 01:23 AM..
  #5 (permalink)  
Old 10-20-2008
freelong freelong is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 38
use SED i option.
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 09:35 PM.


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