Replacing certain positions in lines with spaces

Hello,

I have a file with hundreds of lines. Now I need to replace positions 750-766 in each line (whatever there is there) with spaces... how can I do that?

Which command to use?

The result will be all the lines in the file will have spaces in positions 750-766.

Thanks!

Try

sed 's/\(.\{749\}\).\{17\}/\1                 /' file

why 749 when I wanted 750-766?

and after I pasted the command is says:
"cannot be parsed."

Any suggestions?

Thanks.

Not sure why, the command seems to be correct. What is your OS and version?

Good question: when you want to change "from position 750" that means that the first 749 characters in the line should go unchanged. What RudiC does is to read each line up to character 766 in two parts: the first 749 characters and then 17 characters. The first part is then put to output unchanged (the "\1", which is a so-called "back-reference"), the second part is replaced by 17 blanks.

I hope this helps.

bakunin

1 Like