![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| rsh to change multiple ip in multiple servers? | kenshinhimura | Shell Programming and Scripting | 2 | 02-18-2008 12:04 AM |
| About NIMs | Mustur007 | AIX | 1 | 08-14-2007 01:06 PM |
| Career Path/Change - Cert Help | CoopDeVille | What's on Your Mind? | 2 | 06-15-2007 05:41 PM |
| Change Default Path ? | tkbharani | UNIX for Advanced & Expert Users | 4 | 01-14-2007 12:53 AM |
| How to loop thru and change multiple files in realtime system? | merliech | Shell Programming and Scripting | 2 | 04-24-2006 09:25 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
to change a path /appl/nims with an /appl2/nimsrobt in multiple files using sed
Hi All,
I have developed a script in which i have taken the path from the user in a variables named FromPath and ToPath. I want to replace the FromPath with ToPath. For that I am using sed command in the following way. cp $file bk_$file FromPath=/appl/nims/nimsc1 FromPath=`echo $FromPath | sed 's/\//\\//g' It should return \/appl\/nims\/nimsc1 to use it in SED command. sed 's/$FromPath/$ToPath/g' bk_$file > $file But it is not working and it is raising an error command garbled. It is working fine on the unix prompt. but in script it is raising an error. So please co-operate me and tell me what wrong I am doing. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
something like this
Code:
echo $FromPath| sed 's/\//\\\//g' |
|
#3
|
|||
|
|||
|
Thank you for you reply but i am gettinng an error.
I have already tried the script you have given. the error is sed: command garbled: s/\//\\//g. It is working on the unix prompt but not in script.
My some portion of the code is as below FromPath=`echo $FromPath | sed 's/\//\\\//g'` ToPath=`echo $ToPath | sed 's/\//\\\//g'` From_UIDPWD=`echo $From_UIDPWD | sed 's/\//\\\//g'` To_UIDPWD=`echo $To_UIDPWD | sed 's/\//\\\//g'` echo $From_UIDPWD $To_UIDPWD $FromPath $ToPath $From_ORA_SID $To_ORA_SID cd scripts for file in my_*.sh do echo $file if [ -w $file ] then cp $file bk_$file #sed 's/$From_UIDPWD/$To_UIDPWD/g;s/$FromPath/$ToPath/g;s/@$From_ORA_SID/@$To_ORA_SID/g' bk_$file > $file sed 's/@$From_ORA_SID/@$To_ORA_SID/g' bk_$file > $file rm bk_$file else echo "The file $file is read only file." | tee -a CouldNotChangeFile.log fi done Suggest me something to solve this problem. |
|
#4
|
|||
|
|||
|
This is not needed.
Code:
FromPath=`echo $FromPath | sed 's/\//\\//g' It should return \/appl\/nims\/nimsc1 to use it in SED command. Code:
sed "s;$FromPath;$ToPath;g" bk_$file > $file |
|
#5
|
|||
|
|||
|
|
|||
| Google The UNIX and Linux Forums |