Is there a way to print a regexp match (but only the matching string) using awk
command in shell?
Yes, in awk
use the match()
function and give it the optional array parameter (a
in my example). When you do this, the 0-th element will be the part that matched the regex
$ echo "blah foo123bar blah" | awk '{match($2,"[a-z]+[0-9]+",a)}END{print a[0]}' foo123
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With