I’m trying to do a bit of group matching using sed.
Basically I have something like this:
func_name(4234,43543,76,1)
And I need to match the parameters of the function:
$ echo 'func_name(4234,43543,76,1)' | sed -n 's/\([0-9][0-9]*\).*/\1 /p'
func_name(4234
$ echo 'func_name(4234,43543,76,1)' | sed -n 's/\([[:digit:]]+\).*/\1 /p'
<empty>
$ echo 'func_name(4234,43543,76,1)'| sed -n 's/.*\([0-9][0-9]*\).*/\1 /p'
1
If you know the number of parameters and they are always ‘simple’ (no nested parentheses and hence no embedded commas either), then:
Note that this tolerates spaces after the commas (and before them too – but you wouldn’t leave spaces before, would you?).
Or, if the parameters are simple unsigned integers and you know the function name, maybe:
To get all the parameters in a single match, you have to do nested grouping:
Now
\2..\5still refer to the separate arguments.This uses the repeat control
\{3\}to find the arguments after the first.