I need to use regexs to parse specific lines of a data file. My test command with match works, and my test command for specific line numbers work, but when I put them together, I get no output.
gawk 'NR==42 {print $0}' filename
prints out the entirety of line 42
gawk 'match($0, /([0-9]+)/, a) {print NR ":" a[1]}' filename
has a lot of print outs, but specifically has this output: 42:137674 So, my line 42 has a numeric match
gawk 'NR==42 match($0, /([0-9]+)/, a) {print NR ":" a[1]}' filename
doesn't print anything out, and I have no idea why.
I have a work around:
gawk 'match($0, /([0-9]+)/, a) {if (NR==42) print NR ":" a[1]}' filename
But I believe it's less performant, so would like to figure out why the other command doesn't work
EDIT: Answered, I totally forgot about && between the NR and match