I am trying to fill a file with a sequence of random 0 and 1s with a user-defined number of lines and number of characters per line.
the first step is to get a random stream of 0 and 1s:
cat /dev/urandom | tr -dc 01
then I tried to fill a file with this stream (and end the process of filling by ctrl+c)
cat /dev/urandom | tr -dc 01 > foo
when I count the numbers of lines of the so created foo file I get 0 lines.
cat foo | wc -l 0
Now I tried to control the stream, so I created a named pipe and directed the stream into it. Then I made a connection to the named pipe with the dd command in vain hope to control this way the amount of characters per line and number of lines in the file.
makefifo namedpipe
cat /dev/urandom | tr -dc 01 > namedpipe
dd if=namedpipe of=foo bs=10 count=5
the foo file got indeed filled with 50 byte of 0 and 1 , but the number of lines was still 0.
How can I solve it, I guess maybe I have to insert each number of characters a newline into the file, but if so , I do not know how.
Best Answer
How about
fold
? It's part of coreutils...Or if that's not available, some flavour of
awk
:Or you could just do something with a loop...
I'm sure there are other ways... I thought maybe hexdump with a custom format could do it, but apparently not... ;)