![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| converting hex to dec | aismann | Shell Programming and Scripting | 4 | 02-26-2008 02:51 AM |
| Converting \0 to a \n | ajcannon | Shell Programming and Scripting | 2 | 09-28-2007 08:30 AM |
| Converting | seeyou | SCO | 3 | 01-19-2006 11:22 AM |
| converting .txt | laila63 | UNIX for Dummies Questions & Answers | 4 | 06-30-2004 01:56 PM |
| converting kb to mb | csaunders | UNIX for Dummies Questions & Answers | 1 | 02-26-2004 01:14 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
sed converting / to \/
Hi all,
I am using sed for converting a string of type /abc/def/gh by \/abc\/def\/gh [trainee@LINUX ~]$ edu="/home/abc/dec" When I echo that variable and pass it to sed ,it works fine... [trainee@LINUX ~]$ echo $edu|sed 's/\//\\\//g' \/home\/abc\/dec But When I try to store in a variable , it shows the following error [trainee@LINUX ~]$ ued=`echo $edu|sed 's/\//\\\//g'` sed: -e expression #1, char 9: unknown option to `s' HELP BLEAZ Last edited by sakthi.abdullah; 12-12-2006 at 06:23 AM. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Code:
echo "a/b/d" | sed 's#/#\\/#g' |
|
#3
|
|||
|
|||
|
Can you explain this further because
Usually it's of the form s/old/new/g but sed 's#/#\\/#g' contains only s/.../g |
|
#4
|
|||
|
|||
|
Quote:
like abc=`echo "a/b/d" | sed 's#/#\\/#g'` |
|
#5
|
||||
|
||||
|
Quote:
Code:
[~]$ abc=`echo "a/b/d" | sed 's#/#\\/#g'` [~]$ echo $abc a/b/d [~]$ abc=$(echo "a/b/d" | sed 's#/#\\/#g') [~]$ echo $abc a\/b\/d [~]$ Edit Ah ! Here's how it goes with the backticks. Code:
[/tmp]$ abc=`echo "a/b/d" | sed 's#/#\\\\/#g'` [/tmp]$ echo $abc a\/b\/d Code:
When the old-style backquote form of substitution is used, backslash
retains its literal meaning except when followed by $, ?, or \. The
first backquote not preceded by a backslash terminates the command sub-
stitution. When using the $(command) form, all characters between the
parentheses make up the command; none are treated specially.
Last edited by vino; 12-12-2006 at 10:22 PM. |
|
#6
|
||||
|
||||
|
Backtick version:
abc=`echo "a/b/d" | sed 's#/#\\\\/#g'` but I strongly prefer $(...) to `...` for many reasons. |
|
#7
|
|||
|
|||
|
Quote:
|
|||
| Google The UNIX and Linux Forums |