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

后端 未结 8 1568
日久生厌
日久生厌 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.

    0 讨论(0)
  • 2021-01-31 09:25

    The fact that you are substituting author: 00000000000 is already said in sed when you add the s before the first /.

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