-1

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.

Mochael_DLite
  • 167
  • 2
  • 5
  • 14

2 Answers2

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
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