Does lookbehind work in sed?

后端 未结 2 1724
天命终不由人
天命终不由人 2020-12-01 10:48

I created a test using grep but it does not work in sed.

grep -P \'(?<=foo)bar\' file.txt

This works correctly

2条回答
  •  清歌不尽
    2020-12-01 11:09

    GNU sed does not have support for lookaround assertions. You could use a more powerful language such as Perl or possibly experiment with ssed which supports Perl-style regular expressions.

    perl -pe 's/(?<=foo)bar/test/g' file.txt
    

提交回复
热议问题