Return a regex match in a Bash script, instead of replacing it

前端 未结 9 762
面向向阳花
面向向阳花 2021-01-31 04:30

I just want to match some text in a Bash script. I\'ve tried using sed but I can\'t seem to make it just output the match instead of replacing it with something.



        
9条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-31 04:44

    Pure Bash. Use parameter substitution (no external processes and pipes):

    string="TestT100String"
    
    echo ${string//[^[:digit:]]/}
    

    Removes all non-digits.

提交回复
热议问题