Replace characters in a file by index

I am looking for a reliable method to replace a sequence of characters in a text file. I know that the file will always follow a certain format and that I need to replace a certain range of characters (that is, start with char 20, replace the next 11 characters with "#")

I found some examples using sed and awk that do this on most files. However, the freeze in my case is that the range of characters in the file contains random mascot characters including several NULL characters. This causes the processing of file commands to stop.

I know that the easiest solution would be to go to the process that creates the file, and not insert a file with NULL characters. However, the file is generated by a process buried in ancient COBOL running on the mainframe, and any changes there require almost an act of congress.

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

Thanks in advance.

+1
source share
1 answer

GNU dd can do this

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

Ensure that the echo command provides enough characters as input.

+4
source

Source: https://habr.com/ru/post/1432254/


All Articles