Re:The State of the Awk (2020)
by burntsushi on Thursday January 19, 2023 @08:51AM
(#34440222)
ripgrep can do it! :)
or more succinctly:
Example:
Named groups work too:
You can also replace the whole match by combining --replace with --only-matching:
Of course, I understand capturing groups are useful to have in awk when you're using awk. ripgrep can only handle very simplistic cases. But they tend to be quite common.
[ Parent
| on HN ]
I've needed these capabilities often while using awk for converting messy logs/error outputs into tables/commands.
Nowadays I like the nushell approach to the composition:
echo 'quux=123 foo=123 bar=123' | str replace '.*quux=([0-9]+).*foo=([0-9]+).*' $"$2,$1" | from csv -n | each {|r| $r.column1 + $r.column2}
which of course relies on the same regex library (hattip).It can't be comfortably used as part of a larger Awk script.
Re:The State of the Awk (2020)
by burntsushi on Friday January 20, 2023 @08:50AM
(#34453070)
Yes, as I acknowledged generally in the end of my comment.