Replace based on an exact position

Trying to use sed - but having no luck.

I have a text file - I want to replace whatever character is in position 106, 157 and 237 w/ the string "xxx". Want this change for all lines w/in that text file.

I'm open to using awk or whatever command would be best for replacing characters based on the exact position. Seems like sed can do a lot, but for whatever reason, have had no luck figuring out how to replace on just position alone.

Thanks much!

I know its Perl, and it looks ugly, but if you don't mind that then here it goes:

perl -pe 's/(.{105}).(.{50}).(.{79}).(.*)/\1xxx\2xxx\3xxx\4/' file > out.file

I hope I didn't mess numbering :wink:

works great. thanks again!

sed -n 's/\(.\{105\}\).\(.\{50\}\).\(.\{79\}\).\(.*\)/\1XXX\2XXX\3X\4/gp'  sample_file
sed 's/./xxx/237;s/./xxx/157;s/./xxx/106' infile
awk -F "" '{for (i=1;i<=NF;i++) if (i==106||i==157||i==237) $i="xxx"}1' OFS="" urfile