I'm trying to build a simple script which randomises data. I will make it very simple.
Let's say I have the following data inside data.txt: 11 222 333 4444 55555
So basically some numbers delimited by a space.
What I want is to add letters from a
to h
after each digit. Randomly selected from an array or from a file.
The problem is after executing the script, I get the same variable value after each letter.
Expected result: 1a1b 2f2a2e 3e3b3d 4a4g4h4c 5a5d5f5a5c
What I get is: 1g1g g2g2g2g g3g3g3g g4g4g4g4g g5g5g5g5g5
Script looks like this:
#!/bin/bash
letters=("a" "b" "c" "d" "e" "f" "g" "h")
random=$(shuf -i 1-9999 -n 1)
result=${letters[$random % ${#letters[@]}]}
result2=$(awk '$1=$1' FS= OFS="$result" $1)
echo $result2;