How do you “debug” a regular expression with sed?

后端 未结 8 1587
日久生厌
日久生厌 2021-01-31 08:19

I\'m trying to use a regexp using sed. I\'ve tested my regex with kiki, a gnome application to test regexpd, and it works in kiki.

date: 2010-10-29          


        
8条回答
  •  庸人自扰
    2021-01-31 09:21

    You are using the -i flag incorrectly. You need to put give it a string to put on the temporary file. You also need to escape your curly braces.

    sed -ibak -e "s/author:\s[0-9]\{11\};//g" /tmp/test_regex.txt
    

    I usually debug my statement by starting with a regex I know will work (like 's/author//g' in this case). When that works I know that I have the right arguments. Then I expand the regex incrementally.

提交回复
热议问题