LinuxQuestions.org
Visit the LQ Articles and Editorials section
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 09-02-2011, 02:53 AM   #1
dinakumar12
Member
 
Registered: Mar 2010
Location: INDIA (chennai)
Distribution: centos
Posts: 268
Blog Entries: 7

Rep: Reputation: 18
different options in sed


Hi all,

I use sed to do basic string replace options in files.But i have a doubt.

Consider i have a path like this inside a file.

/home/dinesh/scripts

And i need to replace this with

/var/tmp/scripts.

I tried this with sed but failed all the time.Can any one help me to get this working through "sed".

Thanksin advance,
Dinesh.
 
Old 09-02-2011, 03:12 AM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950
How about showing us the actual command(s) you tried, so we can point out where you went wrong?

The most likely culprit however, is that the slashes in the text conflict with the slashes in sed's substitution command. This is easily fixed, just by using a different delimiter (you could also backslash-escape them, but why bother?).
Code:
sed 's|/home/dinesh/scripts|/var/tmp/scripts|'
Here are a few useful sed references.
http://www.grymoire.com/Unix/Sed.html
http://sed.sourceforge.net/sedfaq.html
http://sed.sourceforge.net/sed1line.txt
 
1 members found this post helpful.
Old 09-02-2011, 03:29 AM   #3
dinakumar12
Member
 
Registered: Mar 2010
Location: INDIA (chennai)
Distribution: centos
Posts: 268
Blog Entries: 7

Original Poster
Rep: Reputation: 18
Hi,

As you suugested it worked after executing this,


sed -i 's|/home/dinesh/scripts|/var/tmp/scripts/|'g file

Thanks.
 
Old 09-04-2011, 09:02 PM   #4
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
Quote:
you could also backslash-escape them, but why bother?
Indeed; there's even an expression for the result 'Leaning toothpick syndrome' https://secure.wikimedia.org/wikiped...hpick_syndrome
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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] modifying stream id of ip options Error options (unknown 136) MegaMindd Programming 0 06-07-2011 10:17 AM
[SOLVED] sed 's/Tb05.5K5.100/Tb229/' alone but doesn't work in sed file w/ other expressions Radha.jg Programming 6 03-03-2011 08:59 AM
sed: how to change MAC address string with sed cold Linux - Software 5 08-02-2010 08:43 AM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 07:12 AM
sed options niidea Programming 2 09-20-2003 02:15 PM


All times are GMT -5. The time now is 11:11 AM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration