Here you are:
sed 's/\(.\{1\}\)/\1 /g' input > output
And if you want to save the changes in-place:
sed -i 's/\(.\{1\}\)/\1 /g' input
How it works:
s/\(.\{1\}\)/\ /g
will add a space, after each 1 character.
For instance, if you wanted an output file like:
12 12 10 31 22
12 33 32 12 12
00 00 02 22 21
You could edit my answer to:
sed -i 's/\(.\{2\}\)/\1 /g'
So it will add a space, after each 2 characters.
In addition, /\1 /
is the same as /&
, and will add one white-space.
For instance, to add three: /\1 /
or /& /
. You have many more options to use. Sed is a super-powerful tool.
In addition yes, as @Law29 mentioned, this will leave a space at the end of each line if you do not remove, so to remove them while adding spaces you can add a s/ $//
to the end of given solution, to do so:
sed 's/./& /g; s/ $//'
I hope this could help.