I’m trying to replace a small amount of text on a specific line of a large log file (totaling ~40 mil lines):
sed -i '20000000s/.\{5\}$/zzzzz/' log_file
The purpose of this is to “mark” a line with an expected unique string, for later testing.
The above command works fine, but in-place editing of sed (and perl) creates a temp file, which is costly.
Is there a way to replace a fixed number of characters (i.e. 5 chars with 5 other chars) in a file without having to create a temp file, or a very large buffer, which would wind up becoming a temp file itself.
You could use
ddto replace some bytes in place:would write 10 zeros (0x00) after the 1000s byte. You can put whatever you want to replace inside a file and write the path to it in the
ifparameter. Then you had to insert the size of the replacement file into thecountparameter, so the whole file gets read.the
conv=notruncparameter tellsddto leave the end of the file untruncated.This should work well for any 1-byte file encoding.