-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestFile.sh
67 lines (56 loc) · 1.38 KB
/
testFile.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
virusesFile=$1
countriesFile=$2
#typechecking ints
if [ $3 -lt 0 ]
then
echo "Invalid num of lines"
exit
else
numLines=$3
fi
if [ $4 -lt 0 ]
then
echo "Invalid num for duplicates"
exit;
else
duplicatesAllowed=$4
fi
#creating array with numLines countries
num_countries=0
set countries
while read line; do
countries[num_countries]=$line
num_countries=$((num_countries+1))
done < $countriesFile
#creating array with numLines viruses
num_viruses=0
set viruses
while read line;
do
viruses[num_viruses]=$line
num_viruses=$((num_viruses+1))
done < $virusesFile
#creating inputFile
touch inputFile.txt
#writing records in inputFile
i=0
while [ $i -lt $numLines ]
do
# generating random data for an entry
if [ $duplicatesAllowed == 0 ]
then # no duplicates
id=$($i + 1) # getting ids serially to prevent duplicates
else # duplicates
id=$RANDOM # getting random ids
fi
first_name=$(cat /dev/urandom | tr -dc 'a-zA-Z' | fold -w 10 | head -n 1)
last_name=$(cat /dev/urandom | tr -dc 'a-zA-Z' | fold -w 10 | head -n 1)
country=${countries[$RANDOM % $num_countries]}
age=$(($RANDOM % 121))
virus=${viruses[$RANDOM % $num_viruses]}
vaccinated=$(($RANDOM % 2))
#print data in file
echo "$id $first_name $last_name $country $age $virus $vaccinated" >> inputFile.txt
i=$(($i + 1))
done
echo "Input file ready"