Results 1 to 4 of 4
Hi,
Need to replace dir DIR_SCRIPTS=/user/iprcce/dbg_tool/scripts with DIR_SCRIPTS=$basePath/scripts/scripts.
I tried to replace a directory which is in a variable using sed command. But it didn't work. Can u'll plase help ...
- 04-14-2009 #1Just Joined!
- Join Date
- Apr 2009
- Posts
- 2
sed command to replace directory
Hi,
Need to replace dir DIR_SCRIPTS=/user/iprcce/dbg_tool/scripts with DIR_SCRIPTS=$basePath/scripts/scripts.
I tried to replace a directory which is in a variable using sed command. But it didn't work. Can u'll plase help me.
$basePath=/user/iprcce/dbg_tool
sed -e "s/DIR_SCRIPTS=\/user\/iprcce\/dbg_tool\/scripts/DIR_SCRIPTS=\"${basePath}\"\/scripts\/scripts/g
" $TMP > tmp1
mv tmp1 fileout
I am using ksh shell, i have tried some thing like this also sed 's_/i01/proc_/dwftp/scripts_g' ex2 > filename.tmp
but it didnt work.
Thanks in advance!
- 04-14-2009 #2
From your code it is not clear what you are trying to do. I will assume you are trying to replace all references of "/user/iprcce/dbg_tool/scripts" to "/user/iprcce/dbg_tool/scripts/scripts"
Make sure you set up the variable $TMP to actually be a file before this lineCode:sed -e "s#DIR_SCRIPTS=/user/iprcce/dbg_tool/scripts#DIR_SCRIPTS=/user/iprcce/dbg_tool/scripts/scripts#g $TMP > tmp1
Linux User #453176
- 04-15-2009 #3Just Joined!
- Join Date
- Apr 2009
- Posts
- 2
Thanks for the reply
About the variable........
need to replace \/user\/iprcce\/dbg_tool with the variable $tmp where $tmp=\/user\/rappikat\/remote2
tried this, but didnt work out. Can u please help me.....
sed -e 's/DIR_SCRIPTS=\/user\/iprcce\/dbg_tool\/scripts/DIR_SCRIPTS="${tmp}"\/scripts\/scripts/g' $TMP
> tmp1
Thanks in advance.
- 04-15-2009 #4
When setting the variable omit the $
Then you can use a sed command:Code:basePath="DIR_SCRIPTS=/user/rappikat/remote2"
Code:sed -e "s#DIR_SCRIPTS=/user/iprcce/dbg_tool#$basePath#g" $TMP > tmp1
Linux User #453176


Reply With Quote