- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Sed Command
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
тАО04-18-2009 02:39 AM
тАО04-18-2009 02:39 AM
Sed Command
temp=`echo "$1" | sed "s/'/\\\\\'/g" | sed 's/ /\\\\ /g'`
Please explain with example. Thanks a lot.
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-18-2009 03:50 AM
тАО04-18-2009 03:50 AM
Re: Sed Command
"Life is like a sewer. What you get out of
it depends on what you put into it."
dyi # echo "a'b c'd" | sed "s/'/\\\\\'/g" | sed 's/ /\\\\ /g'
a\'b\\ c\'d
Note, however, that:
dyi # echo "a'b c'd" | sed "s/'/\\\'/g" | sed 's/ /\\\\ /g'
a\'b\\ c\'d
> Please explain with example.
Please supply some context. Is there some
actual problem which you are trying to solve?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-18-2009 04:39 AM
тАО04-18-2009 04:39 AM
Re: Sed Command
And when this pipeline is wrapped in $(), that double backslash is converted into just one.
$ script.sh "xx'yy zz"
xx\'yy\ zz
xx\'yy\\ zz # with just echo
Hmm, it appears sed gets different number of backslashes depending on whether $() or ``.
But it seems the output is the same:
$():
argv[0]: "sed"
argv[1]: "-e"
argv[2]: "s/'/\\\'/g"
argv[3]: "-e"
argv[4]: "s/ /\\\\ /g"
``:
argv[0]: "sed"
argv[1]: "-e"
argv[2]: "s/'/\\'/g"
argv[3]: "-e"
argv[4]: "s/ /\\ /g"
Neither:
argv[0]: "sed"
argv[1]: "-e"
argv[2]: "s/'/\\\'/g"
argv[3]: "-e"
argv[4]: "s/ /\\\\ /g"
>Please explain with example
So basically this (how many backslashes you need) can't be explained very well. :-(
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-20-2009 12:04 PM
тАО04-20-2009 12:04 PM
Re: Sed Command
P.S Since this was part of a generic script, the purpose of which could not be understood, I had to frame such a generic question.
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-20-2009 12:55 PM
тАО04-20-2009 12:55 PM
Re: Sed Command
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-20-2009 02:11 PM
тАО04-20-2009 02:11 PM
Re: Sed Command
/home/test>cat file1
123
'123'
' 123 '
' 123'
'123
' 123
/home/test>sed "s/'/\\\\\'/g" file1
123
\'123\'
\' 123 \'
\' 123\'
\'123
\' 123
/home/test>sed "s/'/\\\\\'/g" file1|sed 's/ /\\\\ /g'
123
\'123\'
\'\\ 123\\ \'
\'\\ 123\'
\'123
\'\\ 123
Not sure of the choice of the number of back slashes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-21-2009 05:33 AM
тАО04-21-2009 05:33 AM
Re: Sed Command
fsm.sh
====================================================
#!/bin/bash
temp=`echo "$1" | sed "s/'/\\\\\'/g" | sed 's/ /\\\\ /g'`
echo $temp
fsm1.sh
====================================================
#!/bin/bash
read temp2
echo $temp2
sample use:
===================================================
A:
./fsm.sh "12 db ' ' 456" > oo.out
./fsm1.sh < oo.out
12 db ' ' 456
B:
./fsm.sh "12 db ' ' 456" | ./fsm1.sh
12 db ' ' 456
As noted previously, its used to maintain qoutes and spacing....