I have a file that contains numbers copied from somewhere. It looks something like this:
{02 12 04 01 07 10 11 06 08 05 03 15 13 00 14 09},
{14 11 02 12 04 07 13 01 05 00 15 10 03 09 08 06},
{04 02 01 11 10 13 07 08 15 09 12 05 06 03 00 14},
{11 08 12 07 01 14 02 13 06 15 00 09 10 04 05 03}
I now have to add comma after every number (basically to make it a C++ array). I tried using sed:
cat file.txt | sed -r "s/ /, /g"
But this prefixes every space with a comma, while I only want them after digits.
If I use cat file.txt | sed -r "s/[0123456789] /, /g"
,
I won't be able to get the same number before replacement.
Thus, I only want to change some part of the substring.
How do I do this?
08
and09
are not valid integer literals.cat file.txt | sed -r 's/([{, ])0+([0-9])+/ \1 \2/g'
which will remove any zeros occurring in the units place