LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 11-24-2006, 11:04 AM   #1
Andrew_OC
LQ Newbie
 
Registered: Nov 2006
Posts: 26

Rep: Reputation: 15
SED Script question


I have a configuration file which contains a line like :

URL=https://target.com:123/folder


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
soggycornflake
Member
 
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.

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


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
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


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

Main Menu
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