zed
zed copied to clipboard
Creating record fields from regex named captures
Is there a way to add a field with RE2 named capture groups?
zq -Z '/total (?P<total>\S+)/' - <<EOF
{
msg: "total 27"
}
EOF
Output is
{
msg: "total 27"
}
But I'd like to have
{
msg: "total 27",
total: "27"
}
And not need to do
zq -Z 'total:=regexp(/total (\S+)/, msg)[1]' - <<EOF
{
msg: "total 27"
}
EOF
{
msg: "total 27",
total: "27"
}