|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
SED conflicting with shell script special char
File 'aa' has path to some files. If it starts with './' then I want to replace it with the current directory. For eg
File aa ------- ./10211/abc.txt ./10347/def.txt I want to transform it into File bb ------- /home/avs/abc.txt /home/avs/def.txt where '/home/avs' is the current working directory [pwd] I have written this script #LOGIC TO REPLACE . WITH PWD ppwwdd="$PWD" sed -e 's/\.\//'"$ppwwdd"'/g' aa > bb When I run the script it gives the error sed: command garbled: s/\.\///home/avs/g I think because sed is not able to recognize special character of forward slash '/' it is giving the error. Any way to get out of this. Thanks Sunil |
|
#2
|
|||
|
|||
|
When you do a sed command like this:
sed 's/cat/dog/' it is not required that you use slashes as the separator character. This would would just as well: sed 's=cat=dog=' Your problem is that you are using slashes as the separator character and slashes also appear in the value contained in your variable. The easiest solution is to switch to another separator character. |
|
#3
|
|||
|
|||
|
Great. It worked.
I knew about this but forgot to use. Thanks a lot sed -e 's=\.\/='"$PWD"'=g' aa > bb |
|
#4
|
|||
|
|||
|
yes avs, the = trick is ok, but
a) instead of: sed -e 's=\.\/='"$PWD"'=g' aa > bb try: sed "s=\.\/=$PWD=g" aa > bb b) i prefer the traditional way PWD=`pwd|sed 's/\//\\&/g'` and the normal sed: s "/^\./$PWD/" NOTA: the correct path of: ./10211/abc.txt is /home/avs/10211/abc.txt not /home/avs/abc.txt Last edited by guggach : August 23rd, 2004 at 09:42 AM. Reason: typo |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > SED conflicting with shell script special char |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|