Reputation: 6661
I have a large file, several gig of binary data, with an ASCII header at the top. I need to make a few small changes to the ASCII header. sed
does the job, but it takes a fair bit of time since the file is so large. vi/vim
is slow too. Is there any linux utility that can just go into the file, make the change at the top, and then get out quickly?
An example might be a header that looks like:
Code Rev: 3.5
Platform: platform1
Run Date: 12/13/16
Data source: whatever
Restart: False
followed by a large amount of binary data ....
and then I might need to, for example, edit an error in "Data source".
Upvotes: 0
Views: 499
Reputation: 101
Provided that you know that your header is less than X bytes, you can use dd. (!) But it only works if both strings have the same length (!)
Lets say, that the header is less that 4096 bytes
dd if=/path/to/file bs=4096 count=1 | sed 's/XXX/YYY/' | dd of=/path/to/file conv=notrunc
You can also do it programmatically, using languages like C,Python,PHP,JAVA etc. The idea is to open the file, read the header, fix it, and write it back.
Upvotes: 3