how to use sed, awk, or gawk to print only what is matched?

后端 未结 11 488
长情又很酷
长情又很酷 2021-01-30 05:59

I see lots of examples and man pages on how to do things like search-and-replace using sed, awk, or gawk.

But in my case, I have a regular expression that I want to run

11条回答
  •  生来不讨喜
    2021-01-30 06:47

    My sed (Mac OS X) didn't work with +. I tried * instead and I added p tag for printing match:

    sed -n 's/^.*abc\([0-9]*\)xyz.*$/\1/p' example.txt
    

    For matching at least one numeric character without +, I would use:

    sed -n 's/^.*abc\([0-9][0-9]*\)xyz.*$/\1/p' example.txt
    

提交回复
热议问题