I have a very large file (21G) and I want to do a find/replace hex (find 20 and replace with 00). I was using tr < filename* -d '\000' > newfilename
Obviously, this is only removing NULL. Any help would be amazing.
Asked
Active
Viewed 3,662 times
-1

Mochael_DLite
- 167
- 2
- 5
- 14
-
Are you wondering how to replace, or how to handle the large file? – blackbird Oct 23 '15 at 20:13
-
Seems like a job for sed rather than tr. – Erik Oct 23 '15 at 20:57
2 Answers
1
Try:
$ sed 's/\x20/\x00/g' file > newfile
Or even
$ sed -i 's/\x20/\x00/g' file
If you don't want to copy the file and just to replace the values in the source file

Roman Pustylnikov
- 1,937
- 1
- 10
- 18
-
-
-
I tried this and it seems to have worked fine: tr < oldfile* -d '\000''\040' > newfile – Mochael_DLite Oct 23 '15 at 19:43
-
1Great, it's always more than one way to do something in linux. – Roman Pustylnikov Oct 23 '15 at 19:51
1
Not sure I understand your question... you say you want to replace hex 20 with hex 0, yet you use a command to delete hex 20 rather than replace it?
Anyway, in general, the command to replace character a
with character b
in a file is:
tr 'a' 'b' < inputFile > outputFile
In your case, you want to replace hex 20, but tr
only likes octal, so you now have two choices... either change the hex 20 to octal 40 for tr
yourself:
tr '\040' '\000' < inputFile > outputFile
or, let the shell translate your hex 20 into something that tr
can understand using:
tr $'\x20' '\000' < inputFile > outputFile
This last form is called ANSI C Quoting
and is described here.

Mark Setchell
- 191,897
- 31
- 273
- 432
-
I was mistaken. I had it backwards, which is why the previous worked – Mochael_DLite Oct 27 '15 at 23:12