The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

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 11:16 AM
how to insert a line number on every line mopimp UNIX for Dummies Questions & Answers 3 03-25-2006 10:35 AM
insert word in each line of a file atticus Shell Programming and Scripting 7 03-22-2006 11:15 PM
insert a line in a file RishiPahuja Shell Programming and Scripting 7 06-22-2005 12:47 AM
Insert a line as the first line into a very huge file shriek UNIX for Advanced & Expert Users 3 03-08-2005 10:22 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 08-17-2007
Registered User
 

Join Date: Jun 2007
Posts: 80
Insert a line

Hi Guys!!!!!!!!!!

I have an input file


say

abcdef
123456
aaaaaa



i need to insert a line say "bbbbbb"
between abcdef and 123456


so that my o/p is

abcdef
bbbbbb
123456
aaaaaa

How to achieve it?
Thanks in advance
Reply With Quote
Forum Sponsor
  #2  
Old 08-17-2007
Registered User
 

Join Date: May 2007
Posts: 211
Code:
sed '/abcdef/a \bbbbb' your_file > new_file
Reply With Quote
  #3  
Old 08-18-2007
Registered User
 

Join Date: Sep 2006
Posts: 55
same file dosen't get updated.

Quote:
Originally Posted by lorcan View Post
Code:
sed '/abcdef/a \bbbbb' your_file > new_file

when i tried the following one:-

sed '/abcdef/a \bbbbb' your_file > your_file. the contents of your_file got deleted. why it was so.
Reply With Quote
  #4  
Old 08-18-2007
Registered User
 

Join Date: May 2007
Posts: 211
Quote:
Originally Posted by bishweshwar View Post
when i tried the following one:-

sed '/abcdef/a \bbbbb' your_file > your_file. the contents of your_file got deleted. why it was so.
You cannot change the contents of the file using sed but the output could be redirected to a new file. If you are going to redirect the same to the input file then it would result in a empty input file.
Reply With Quote
  #5  
Old 08-18-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,610
Quote:
Originally Posted by lorcan View Post
You cannot change the contents of the file using sed but the output could be redirected to a new file. If you are going to redirect the same to the input file then it would result in a empty input file.
you can edit the same file with sed

using the " -i " option but that is available only as GNU sed option.

Code:
sed -i 's/search/replace/g' inputfile
Reply With Quote
  #6  
Old 08-19-2007
Registered User
 

Join Date: Jun 2007
Posts: 80
Thanks Guys!!!!!!!!!!!!!!!

But have a doubt ..
If suppose my input contains space...
For ex:

I/p File:

abc def
aaaaa
abc def
bbbbb


No i want to add the pattern 12345 after abc def so that my o/p file wil be


abc def
12345
abc def
bbbbb
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 10:02 AM.


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 Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0