Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am running this:

cat /dev/urandom|hexdump| grep -i "ffff f" > random

and I get nothing in file random, it remains zero length after the command is interrupted.

How to make it writing output to a file?

I need to write a result to a file, which should contains output data like this:

021bc40 7724 d4f5 59ec bcbb ffff fd26 ab3c 9b7c

03a9100 b3a5 8601 fa33 ffff f23c 4326 2e7f 0c8a

0449810 e459 d5af 4e11 ffff fc55 8660 9efb 3c9b

enter image description here

share|improve this question
up vote 9 down vote accepted

Use the --line-buffered option for grep (and also get rid of the useless cat):

hexdump /dev/urandom | grep --line-buffered -i "ffff f" > random

This way the output is not buffered but every line put into random immediately. I would also recommend to use tee in your pipe to see how many lines have been produced:

hexdump /dev/urandom | grep --line-buffered -i "ffff f" | tee random
share|improve this answer
Perfectly does the trick. Thank you very much. – Ruslan Gerasimov Jun 26 '14 at 9:06

Your file is empty because the process is interrupted before the file is written to disk. That is how redirection works. As a workaround, try this:

script -c 'cat /dev/urandom|hexdump|grep -i "ffff f"' -f random

This will basically write all screen output to the file.

share|improve this answer
It involved one more command, but delivered. Thank you. – Ruslan Gerasimov Jun 26 '14 at 9:05

cat /dev/urandom|hexdump or hexdump /dev/urandom writes continuously to the stdout and if you press Ctrl+C nothing will be executed after this. But you can limit the output with head

hexdump /dev/urandom | head -n1000000 | grep "ffff f" > random  

this will grep in the first 1000000 lines of the output and writes the result to a file.

share|improve this answer
Involved one more command, but gave a good result. Thank you. – Ruslan Gerasimov Jun 26 '14 at 9:07

You will need to write the output of cat /dev/urandom | hexdump to a file before you execute it the next time. The script below should accomplish what you are trying:

cat /dev/urandom | hexdump |
  while IFS= read -r line; do
    printf '%s\n' "$line" >> random;

IFS is used to split the output into lines here.


share|improve this answer
grep "ffff f" missed – Ruslan Gerasimov Jun 26 '14 at 8:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.