Abhimanyu Khanna Abhimanyu Khanna - 7 months ago 35
Bash Question

Filling a column with random data bash

I have a file with 3 columns of the format

< string > <32 bit number> <48 bit number>

How can I use bash to replace the numbers in 3rd column to be 48 bit random numbers?


That should do the trick:

while read a b c; do
    echo $a $b $(cat /dev/urandom | tr -dc '0-1' | fold -w 48 | head -n 1)
done < input > output

a is the string (I assume there are no spaces), b is the 32 bit number, c is the 48 bit number that will not be used subsequently. Instead we replace it with input from /dev/urandom.