Issue
Is there a way to print a regexp match (but only the matching string) using awk
command in shell?
Solution
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
Answered By - SiegeX Answer Checked By - David Goodson (WPSolving Volunteer)