LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-19-2011, 10:33 AM   #1
dinakumar12
Member
 
Registered: Mar 2010
Location: INDIA (chennai)
Distribution: centos
Posts: 271
Blog Entries: 7

Rep: Reputation: 18
finding and replacing whole line using sed


Hi all,

assume that i am having the following line in a file called file1.

triumph and disaster must be treated same.

I want to replace this line with.

follow excellence success will chase you.

is it possible to do this using sed. if possible kindly post me the code.
 
Old 03-19-2011, 11:43 AM   #2
Snark1994
Senior Member
 
Registered: Sep 2010
Distribution: Debian
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
Code:
sed 's/^triumph and disaster must be treated same.$/follow excellence success will chase you./' input.txt
 
1 members found this post helpful.
Old 03-20-2011, 01:54 AM   #3
dinakumar12
Member
 
Registered: Mar 2010
Location: INDIA (chennai)
Distribution: centos
Posts: 271

Original Poster
Blog Entries: 7

Rep: Reputation: 18
Hi,

thanks for your reply but thats not working for me.

the line is not getting replaced.
 
Old 03-20-2011, 05:15 AM   #4
sandy.bhadoriya
Member
 
Registered: Dec 2010
Posts: 31

Rep: Reputation: 3
you can use this think it is in perl and it works.
perl -pi -e 's/text to be replaced/text to be placed' filename
 
1 members found this post helpful.
Old 03-20-2011, 06:03 AM   #5
anishkumarv
Member
 
Registered: Feb 2010
Location: chennai - India
Distribution: centos
Posts: 294

Rep: Reputation: 10
Hi dinakumar12,

Try this it works!!!

sed -i "s/triumph and disaster must be treated same./follow excellence success will chase you./" file1


With Regards
Anish Kumar.V
 
1 members found this post helpful.
Old 03-20-2011, 10:02 AM   #6
dinakumar12
Member
 
Registered: Mar 2010
Location: INDIA (chennai)
Distribution: centos
Posts: 271

Original Poster
Blog Entries: 7

Rep: Reputation: 18
Hi Anish,

Thank you very much for your reply. That works like charm.
 
Old 03-20-2011, 10:07 AM   #7
dinakumar12
Member
 
Registered: Mar 2010
Location: INDIA (chennai)
Distribution: centos
Posts: 271

Original Poster
Blog Entries: 7

Rep: Reputation: 18
Hi snark1994,

Thanks, your code also works, sorry i made some silly mistake while trying.


Once again thanks to snark1994 and Anish.
 
  


Reply

Tags
sed



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Need help in replacing set of characters in a specific line using sed or awk bbachu Programming 15 01-03-2011 01:01 AM
[SOLVED] SED and Replacing Specific Line bridrod Linux - Newbie 6 08-24-2009 12:28 PM
replacing with sed dipuasks Linux - General 13 12-31-2008 11:24 AM
sed replacing line confusion freeindy Programming 12 08-07-2008 04:49 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:12 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration