- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- help with SED
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
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
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
тАО07-07-2003 01:00 AM
тАО07-07-2003 01:00 AM
help with SED
here my script :
##
EXPORIG=toto
NEWEXP=bibi
sed -e 's|"$EXPORIG"|"$NEWEXP"|g' file
##
the syntax in sed command is not correct
i want to replace "$EXPORIG" with "$NEWEXP"
in "file"
how to insert a variable in sed command ?
Thank's
- Tags:
- sed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-07-2003 01:04 AM
тАО07-07-2003 01:04 AM
Re: help with SED
sed "s/$EXPORIG/$NEWEXP/g" file
tested with a pipe command for the file, but still tested!
Share and Enjoy! Ian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-07-2003 01:48 AM
тАО07-07-2003 01:48 AM
Re: help with SED
Ian gave you an answer.
I think that your command was not working because the | was mis-interpreted by the shell.
Simply choosing a different separator will do the trick.
Massimo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-07-2003 03:15 AM
тАО07-07-2003 03:15 AM
Re: help with SED
EXPORIG=toto
NEWEXP=bibi
echo sed \'s/$EXPORIG/$NEWEXP/g\' file > replace.sh
chmod +x replace.sh
./replace.sh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-07-2003 04:51 AM
тАО07-07-2003 04:51 AM
Re: help with SED
whith sed you have need to redirect the output in a new file to save the change.
A friend tell me to try this for change and save in the same file,and its works.
Maybe is a good idea to make a back_up of file befour before!!!!
ed - file << EOF
1,$ s/$EXPORIG/$NEWEXP/g
w file
EOF
Sorry for my english ;)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-07-2003 05:13 AM
тАО07-07-2003 05:13 AM
Re: help with SED
sed -e 's|"$EXPORIG"|"$NEWEXP"|g' file
With this:
eval sed 's/$EXPORIG/$NEWEXP/g' file
Hai
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-07-2003 11:16 AM
тАО07-07-2003 11:16 AM
Re: help with SED
Ian's solution will handle most cases where you did not really want the "'s to appear in the pattern you replace-
sed "s/$EXPORIG/$NEWEXP/g" file
The double quotes will quote the special characters but allow the variables to be expanded.
His solution will have trouble if there are any / symbols in the variables. Using | for the sed substitution will handle / characters in the pattern, but won't handle | characters in the pattern. To handle all strings in the patterns you will need to actively quote the character that you are using to delimit the patterns. Here is an example that uses / characters as the delimiter. The first two sed commands add quoting backslash characters as needed.
QUOTEDEXPORIG="$(print $EXPORIG | sed -e 's|/|\\/|g')"
QUOTEDNEWEXP="$(print $NEWEXP | sed -e 's|/|\\/|g')"
sed -e "s/$QUOTEDEXPORIG/$QUOTEDNEWEXP/g" file
You might want to quote other wildcard characters as well. Here is an example that quotes every special character. It can handle characters like . and * in the patterns.
QUOTEDEXPORIG="$(print $EXPORIG | sed -e 's|[/.[\*^]|\\&|g')"
QUOTEDNEWEXP="$(print $NEWEXP | sed -e 's|[/.[\*^]|\\&|g')"
sed -e "s/$QUOTEDEXPORIG/$QUOTEDNEWEXP/g" file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-07-2003 12:29 PM
тАО07-07-2003 12:29 PM
Re: help with SED
In sed you use "/" and not "|"
do this:
sed "s/${EXPORIG}/${NEWEXP}/g"
Caesar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-07-2003 04:52 PM
тАО07-07-2003 04:52 PM
Re: help with SED
As a point of clarification (and I quote from the 'sed' man pages since it says it so well!)"
"An address is either a decimal number that counts input lines cumulatively across files, a $ which addresses the last line of input,
or a context address; that is, a /regular expression/... In a context address, the construction \?regular expression?, where ? is any character, is identical to /regular expression/."
For substitutions, "s/regular expression/replacement/flags: Substitute replacement string for instances of regular xpression in the pattern space. Any character can be used instead of /."
Regards!
...JRF...