How to replace a path with another path in sed?

前端 未结 7 1634
广开言路
广开言路 2020-12-01 07:30

I have a csh script (although I can change languages if it has any relevance) where I have to:

sed s/AAA/BBB/ file

The problem is that AAA

7条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-01 07:43

    sed can use any separator instead of / in the s command. Just use something that is not encountered in your paths:

    s+AAA+BBB+
    

    and so on.

    Alternatively (and if you don't want to guess), you can pre-process your path with sed to escape the slashes:

    pwdesc=$(echo $PWD | sed 's_/_\\/_g')
    

    and then do what you need with $pwdesc.

提交回复
热议问题