#################################################################
# To Generate a lottery text randomly within 10 different files
#!/bin/bash
#################################################################
file_dir='/backup/files'
array=(file_1 file_2 file_3 file_4 file_5 file_6 file_7 file_8 file_9 file_10)
my_lottery1=$((RANDOM%${#array[@]}))
my_lottery2=$((RANDOM%${#array[@]}))
while [ $my_lottery2 -eq $my_lottery1 ] ;
do
my_lottery2=$((RANDOM%${#array[@]}))
done
counter=0
for i in "${array[@]}"
do
if [ $counter -eq $my_lottery1 ] || [ $counter -eq $my_lottery2 ]
then
echo Index No.$counter $i "got it"
echo "This file contains lottery." > $file_dir/$i
else
echo "This file contains garbage." > $file_dir/$i
fi
((counter++))
done
Index No.3 file_4 got it
Index No.7 file_8 got it
# grep -rnw /backup/files -e 'lottery'
/backup/files/file_4:1:This file contains lottery.
/backup/files/file_8:1:This file contains lottery.
GREP Commands Manual
-R, -r, --recursive
Read all files under each directory, recursively; this is equivalent to the -d recurse option.
-n, --line-number
Prefix each line of output with the line number within its input file.
-w, --word-regexp
Select only those lines containing matches that form whole words. The test is that the matching substring must either be at the beginning of the line, or
preceded by a non-word constituent character. Similarly, it must be either at the end of the line or followed by a non-word constituent character.
Word-constituent characters are letters, digits, and the underscore.