sed insert character at specific positions

In a general way, you can just do:

sed 's/./&,/4' <in >out

That will append a comma on output to the 4th character of all input lines with at least that many characters.

And, if you'll take my advice, you should generally not use the -i switch to any sed which offers one.


Start from the rightmost one:

sed -i 's/./&,/22;s/./&,/8;s/./&,/4' ./*.txt

Otherwise, the first substitution would affect the offset for the second. You can always account for it though:

sed -i 's/./&,/4;s/./&,/9;s/./&,/24' ./*.txt