How to replace a path with another path in sed?

前端 未结 7 1638
广开言路
广开言路 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 08:01

    In circumstances where the replacement string or pattern string contain slashes, you can make use of the fact that GNU sed allows an alternative delimiter for the substitute command. Common choices for the delimiter are the pipe character | or the hash # - the best choice of delimiting character will often depend on the type of file being processed. In your case you can try

    sed -i 's#/path/to/AAA#/path/to/BBB#g' your_file
    

    Note: The g after last # is to change all occurrences in file if you want to change first ouccurence do not use g

提交回复
热议问题