News for hackers. Stuff that matters.
Re:The State of the Awk (2020) by burntsushi on Thursday January 19, 2023 @08:51AM (#34440222)
ripgrep can do it! :)

    rg 'foo=([0-9]+)' --replace '$1'
or more succinctly:

    rg 'foo=([0-9]+)' -r '$1'
Example:

    $ echo 'quux=123 foo=123 bar=123' | rg 'foo=([0-9]+)' -r '$1' 
    quux=123 123 bar=123
Named groups work too:

    $ echo 'quux=123 foo=123 bar=123' | rg 'foo=(?P<digits>[0-9]+)' -or '$digits'
    123
You can also replace the whole match by combining --replace with --only-matching:

    $ echo 'quux=123 foo=123 bar=123' | rg 'foo=([0-9]+)' -or '$1'
    123
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.
Re:The State of the Awk (2020) by nirinor on Thursday January 19, 2023 @09:35AM (#34440677)
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).
Re:The State of the Awk (2020) by ogogmad on Friday January 20, 2023 @02:11AM (#34450034)
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.