LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 03-07-2007, 07:17 AM   #1
sharathkv25
Member
 
Registered: Jul 2006
Distribution: HP-UX
Posts: 46

Rep: Reputation: 15
sed search & replace


Hi,

I have a file 't.env' as follows:

Code:
ORACLE_BASE=/opt/oracle/
ORACLE_HOME=$ORACLE_BASE/bin/forms
How do I replace "$ORACLE_BASE/bin/forms" with my own string using sed?

In sed I used this:

sed -e 's/ORACLE_HOME/ORACLE_HOME=\/opt\/osmf\/config\/env/g' t.txt > t1.tx

But this replaces ORACLE_HOME & not the value after '='

Thanks
 
Old 03-07-2007, 07:25 AM   #2
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 52
Code:
sed -ei 's#\$ORACLE_BASE/bin/forms#my/own/string#g' file.txt
-i for replacing directly in the file (maybe not what you want)
I have replaced the / of sed by #, you can use whatever delimiter you want. Then its more readable.
 
Old 03-07-2007, 10:16 AM   #3
cfaj
Member
 
Registered: Dec 2003
Location: Toronto, Canada
Distribution: Mint, Mandriva
Posts: 221

Rep: Reputation: 31
Quote:
Originally Posted by sharathkv25
Hi,

I have a file 't.env' as follows:

Code:
ORACLE_BASE=/opt/oracle/
ORACLE_HOME=$ORACLE_BASE/bin/forms
How do I replace "$ORACLE_BASE/bin/forms" with my own string using sed?

In sed I used this:

sed -e 's/ORACLE_HOME/ORACLE_HOME=\/opt\/osmf\/config\/env/g' t.txt > t1.tx

But this replaces ORACLE_HOME & not the value after '='
Code:
sed -e 's|$ORACLE_BASE/bin/forms|my/own/string|' t.env
Or:

Code:
sed -e 's|ORACLE_HOME=.*|ORACLE_HOME=my/own/string|' t.env
 
  


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
Does anyone know of a bash script can search & replace txt in a file. jimwelc Linux - Newbie 6 09-15-2008 12:13 AM
Perl Multi-Line Search & Replace... Can I?... donv2 Linux - Newbie 2 01-30-2007 09:59 PM
search & replace raj_sony2001 Linux - General 4 10-05-2006 02:05 PM
Best search & replace program geokker Linux - Software 3 09-28-2005 03:41 PM
trying to search and replace text file for single & multiple line breaks separately brokenfeet Programming 7 08-29-2003 01:56 PM


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

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