Is there a standard command for RedHat (except for the dd + truncate pair) for replacing data with zeros in the middle of a binary file?
2 answers
You can use a one-liner in Python or another scripting language:
python -c "f=open('some','r+b');f.seek(123);f.write('\0'*4);" - Is the resulting length stored? Check for files larger than 4k. - 0andriy
- @ 0andriy, yes, everything is OK. And what is the reason for doubt? - avp
- one@avp should not open binary files in text mode.
with open('file.bin', 'r+b') as f: f.seek(123); f.write(b'\0'*4)with open('file.bin', 'r+b') as f: f.seek(123); f.write(b'\0'*4)although for thisddsufficient. In zsh there is a sysseek.<>allows file to read and write to open. - jfs - Yes, of course it is better to open in binary mode - Abyx
- @jfs, why? I tested in Ubuntu and RedHat. Works. - avp
|
In the piggy bank.
Emacs supports working with binary files as with ordinary files:
Mx hexl-find-file open the file in hex format
CMd insert byte in decimal format.
CMo insert byte in hex format
CMx insert byte in hexadecimal format
Links
- Yes. You can also use the
(quoted-insert)command(quoted-insert)usually attached toCtrl-q) by entering a byte code in the number system specified in the variableread-quoted-char-radix(default 8) - avp
|
$ cat файл1 | tr '\1-\377' '\0' > файл2$ cat файл1 | tr '\1-\377' '\0' > файл2- aleksandr barakinbvihelp? - don Rumatabviwhat is this? - avpemacsalso suitable. I thought, sinceddandtruncatementioned in the question, it is obvious that we are talking about using it in the script (of course, if you wish, you can use the editor from the script) - avp