I wish Awk had capture groups. It would fit in so well with typical Awk one-liners to be able to say:
awk '/foo=([0-9]+)/ { print $1 }'
although I suppose the syntax would have to be different since $1 has a meaning already.Yes, gawk has a function that returns capture groups, but it's a bit verbose for one-liners. Instead I switch to Perl:
perl -nE 'if (/foo=([0-9]+)/) { say $1 }'
But I wish I could just use Awk.I wish grep had capture groups so I could do things like
grep "\((\d+)\)" -print "$1" file.txt
ripgrep is a modern faster grep in Rust, some cons, many pros.
It'll do capture groups with search | replace
# remove square brackets that surround digit characters
$ echo '[52] apples [and] [31] mangoes' | rg '\[(\d+)]' -r '$1'
52 apples [and] 31 mangoes
Pleasantly surprised to see an example from my ebook :)
Add `-o` option to get only the digits:
$ echo '[52] apples [and] [31] mangoes' | rg -o '\[(\d+)]' -r '$1'
52
31
I cite sources way more often than not, this time I got lazy after dithering over whether to go with the definitive ripgrep source page [2] or a decent looking third party(?) tutorial .. pressed for time I did neither.
[1] https://learnbyexample.github.io/learn_gnugrep_ripgrep/ripgr...