0

I've got a file of data from a prototype hardware RNG, however, for some reason it's producing a lot of 0x00 bytes. I want to delete all of these 0x00 bytes so I can test if the rest of the data is random.

How would I go about doing this in the terminal?

6
  • 1
    What has caused you to decide that the 0x00 bytes are not random? How are you creating/writing that file? Commented Dec 5, 2020 at 23:39
  • @AndrewHenle to be honest, they looked like an artifact of something wrong with my transmission process. Removing the null bytes didn't help. I just figured it was worth trying. The data is being produced by a quantum-random number generator I've made and being transmitted to the comp over UART. I've checked the data on a scope and it looks as I'd expect so something's going wrong in my FPGA that's converting the randomness to a bit stream Commented Dec 6, 2020 at 0:54
  • I'm reading it in from a serial port using cat Commented Dec 6, 2020 at 1:10
  • PNG is a binary format so you may not want to remove 0 bytes, but I got a messed up text file which surely doesn't need any zeroes. Commented Jan 2, 2024 at 21:45
  • 1
    @CsabaToth rng is a random number generator, not a typo Commented Jan 3, 2024 at 17:41

1 Answer 1

7
tr -d '\0' <file >newfile 

This deletes all nul bytes in the file file and saves the modified data in newfile.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.