views:

54

answers:

1

I am looking for a reliable method to replace a sequence of chars in a text file. I know that the file will always follow a specific format and that I need to replace a specific range of chars (ie start at char 20, replace the next 11 chars with '#')

I have found several examples using sed and awk which accomplish this on most files. However, the hangup in my case is that the range of chars in the file contain random gibberish chars include several NULL chars. This causes the file commands to stop processing.

I know that the simplest fix would be to go to the process that creates the file and not pad the file with NULL chars. However, the file is generated by a process buried within ancient COBOL running on a mainframe and any changes there require nearly an act of congress.

so, knowing that I am stuck with what I have, is there any way to manipulate the file, from the command line, that can successfully overwrite the NULL chars?

Thanks in advance.

+3  A: 

GNU dd can do that

 echo '###########'|dd  of=FILENAME seek=20 bs=1 count=11 conv=notrunc

Make sure the echo command provides enough characters as input.

Martin v. Löwis
Thanks, that worked perfectly!
Mike Clark