Find the answer to your Linux question:
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 ...
  1. #1
    Just 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!

  2. #2
    Linux Engineer Kieren's Avatar
    Join Date
    Aug 2007
    Location
    England
    Posts
    845
    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"

    Code:
    sed -e "s#DIR_SCRIPTS=/user/iprcce/dbg_tool/scripts#DIR_SCRIPTS=/user/iprcce/dbg_tool/scripts/scripts#g $TMP > tmp1
    Make sure you set up the variable $TMP to actually be a file before this line
    Linux User #453176

  3. #3
    Just 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.

  4. #4
    Linux Engineer Kieren's Avatar
    Join Date
    Aug 2007
    Location
    England
    Posts
    845
    When setting the variable omit the $

    Code:
    basePath="DIR_SCRIPTS=/user/rappikat/remote2"
    Then you can use a sed command:

    Code:
    sed -e "s#DIR_SCRIPTS=/user/iprcce/dbg_tool#$basePath#g" $TMP > tmp1
    Linux User #453176

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...