Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 11-24-2006, 11:04 AM   #1
LQ Newbie
Registered: Nov 2006
Posts: 26

Rep: Reputation: 15
SED Script question

I have a configuration file which contains a line like :


I'm trying to write a script that will use sed to replace the URL information.

By using :

EXISTING_URL=`cat filename | grep URL | cut -d= -f2`

I can see what the existing setting is, by using

cat filename | sed "s/$EXISTING_URL/$NEW_URL/" >new_filename

fails however as sed wants all "/" chars shown as "\/" so it knows not to treat them as it's usual delimiters.

so now I'm stuck as I can't work out how to amend this on the fly
Old 11-24-2006, 12:21 PM   #2
Registered: May 2006
Location: England
Distribution: Slackware 10.2, Slamd64
Posts: 249

Rep: Reputation: 31
Any character can be used as a delimiter, you can also do in-place replacement with the -i option. Also, there is little point in use cat|cut to get the original url, sed can filter this itself. E.g.

sed -i "s|^\(URL=https://\).*$|\1$NEW_URL|" input_file
If you want a backup, use a suffix with -i, such as -ibak


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
Sed shell script question pete1234 Programming 4 08-18-2006 09:15 PM
bash script with grep and sed: sed getting filenames from grep odysseus.lost Programming 1 07-17-2006 11:36 AM
sed script cranium2004 Programming 4 06-21-2006 09:33 AM
sed script glam1 Programming 2 08-31-2004 11:28 AM
sed script help/ideas rjcrews Programming 2 07-30-2004 02:59 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:41 PM.

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