Wednesday, 28 August 2013

Printing all matches in a line using regular expression in awk

Printing all matches in a line using regular expression in awk

Say i have a line:
Terminal="123" Pwd="567"
I want to select only number portion using awk
awk 'match($1, /[0-9]+/){print substr($1, RSTART, RLENGTH)};match($2,
/[0-9]+/){print
substr($2, RSTART, RLENGTH)}' file
This gives the desired result.
123 567.
However there must be other better way to select both numbers without
writing two match statements.
Thanks.

No comments:

Post a Comment