how to get sub-expression value of regExp in awk?
awk, linux, regex
Solution
If you have GNU AWK (`gawk`):
awk '/pay/ {match($0, /"money":"([0-9]+)"/, a); print substr($0, a[1, "start"], a[1, "length"])}' action.log
If not:
awk '/pay/ {match($0, /"money":"([0-9]+)"/); split(substr($0, RSTART, RLENGTH), a, /[":]/); print a[5]}' action.log
The result of either is `100`. And there's no need for `grep`.
Problem
I was analyzing logs contains information like the following: ``` y1e","email":"","money":"100","coi ``` I want to fetch the value of money, i used 'awk' like : ``` grep pay action.log | awk '/"money":"([0-9]+)"/' , ``` then how can i get the sub-expression value in ([0-9]+) ?