How can I change the 'sed' slash (/) delimiter in insert command?

后端 未结 1 797
礼貌的吻别
礼貌的吻别 2021-01-18 05:28

Changing the delimiter slash (/) to pipe (|) in the substitute command of sed works like below

echo hello | sed \'s|he         


        
相关标签:
1条回答
  • 2021-01-18 05:35

    I'm not sure what is intended by the command you mentioned:

    echo hello | sed '/hello/i world'
    

    However, I presume that you want to perform certain action on lines matching the pattern hello. Lets say you wanted to change the lines matching the pattern hello to world. In order to accomplish that, you can say:

    $ echo -e "something\nhello" | sed '\|hello|{s|.*|world|}'
    something
    world
    

    In order to match lines using a regexp, the following forms can be used:

    /regexp/
    \%regexp%
    

    where % may be replaced by any other single character (note the preceding \ in the second case).

    The manual provides more details on this.

    0 讨论(0)
提交回复
热议问题