I have a large file with many instances of variable length lists of numbers in square brackets, max one list per line, list is never empty, e.g.:
[1, 45, 54, 78] or [32]
I want to get rid of the square brackets and the commas, e.g.:
1 45 54 78 or 32
I can successfully match them with this regex in sed:
\\[\\([0-9]*\\)\\(, \\([0-9]*\\)\\)*\\]
but I don't know how to use group numbers to refer to the groups I want, e.g. doing:
sed 's/\\t\[\\([0-9]*\\)\\(, \\([0-9]*\\)\\)*\\]/\\t\\1 \\3/g'
will only result in the destination file getting the first and the last numbers in the list.
(I did solve my problem using awk, but am wondering if it can be done using sed)
Is there any way to refer to variable number of groups in sed?
How about:
Two separate commands - first extracts "stuff inside square brackets", second strips commas.