- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- How to replace a string like $mystring in a file
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2018 02:25 AM
10-04-2018 02:25 AM
Hi,
Here is the content of a file:
...
CURRENT===BLKSIZE=1048576,SBT_LIBRARY=$ORACLE_HOME/lib/libddobk.so,ENV=(STORAGE_UNIT=oramtsrepl,BACKUP_HOST=dedcti1data,ORACLE_HOME=$ORACLE_HOME)
...
How to replace the string $ORACLE_HOME by the value of my environment variable in my file?
note: My environment variable is something like that: /logiciel/app/oracle/product/11.2.0.4
Kind regards,
Den.
Solved! Go to Solution.
- Tags:
- sed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2018 09:02 AM
10-04-2018 09:02 AM
Re: How to replace a string like $mystring in a file
> How to replace the string $ORACLE_HOME by the value of my environment
> variable in my file?
sed?
> note: My environment variable is something like that:
> /logiciel/app/oracle/product/11.2.0.4
What, exactly, is the problem? Evaluating the environment variable,
or dealing with "/", or what?
mba$ export MEV='F/R/E/D'
mba$ echo $MEV
mba$ echo 'xxxx$O_Hyyyy' | sed -e 's|$O_H|'"$MEV"'|'
xxxxF/R/E/Dyyyy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2018 12:40 AM - edited 10-05-2018 12:44 AM
10-05-2018 12:40 AM - edited 10-05-2018 12:44 AM
Re: How to replace a string like $mystring in a file
Hi Steven,
Thank you.
I can simplify the problem with short code:
ORACLE_HOME='/logiciel/app/oracle/product/11.2.0.4'
PRM_PARMS='AA=$ORACLE_HOME is the value of ORACLE_HOME'
echo $PRM_PARMS | sed '.....What is the syntax here....'
echo should return:
AA=/logiciel/app/oracle/product/11.2.0.4 is the value of ORACLE_HOME
I have tried this (and a lot of other variations ;-) without success:
echo $PRM_PARMS | sed 's,'$ORACLE_HOME',$ORACLE_HOME,'
=> does not work
echo $PRM_PARMS | sed -e "s/\$ORACLE_HOME/$ORACLE_HOME/g"
=> does not work
Kind regards,
Den.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2018 06:21 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2018 07:31 AM
10-05-2018 07:31 AM
Re: How to replace a string like $mystring in a file
> echo $PRM_PARMS | sed 's,'$ORACLE_HOME',$ORACLE_HOME,'
You need to do something to keep the shell from treating the first
"$" (only) as special. I used apostrophes.
> echo $PRM_PARMS | sed -e "s/\$ORACLE_HOME/$ORACLE_HOME/g"
You can't use "/" for the sed:s delimiter if "/" appears in the
string.
> echo $PRM_PARMS | sed -e "s+\$ORACLE_HOME+$ORACLE_HOME+g"
Yes, a "\" can do the first job instead of apostrophes, and "+" will
do the second job as well as "|", so long as neither appears in the
string. And "g" will help if you have more than one instance. You
could add a "g" to my suggestion, too.