-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandom
More file actions
executable file
·32 lines (30 loc) · 900 Bytes
/
random
File metadata and controls
executable file
·32 lines (30 loc) · 900 Bytes
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
#!/bin/bash
# print random word
# written by ofek nacht
# enter specific length
echo "number of arg:$#"
if [ $# -eq 2 ]
then
echo -e "special number is $2\n"
# match words length to user demand
MATCHWORD=$(grep -o -w '\w\{'$2'\}' $1)
echo -e "list of matching words:\n$MATCHWORD"
# number of special words
SNUMWORD=$(echo $MATCHWORD | wc -w)
echo "number oif random words is:$SNUMWORD"
# shuffle SPECIAL random number
SNUMRAND=$(shuf -i 1-$SNUMWORD -n 1)
echo "random number is:$SNUMRAND"
# print random SPECIAL word
RANDWORD=$(echo $MATCHWORD | awk '{print}' ORS=" " | awk '{print$'$SNUMRAND'}')
echo "random word is:$RANDWORD"
else
# number pf wprds in a file
NUMWORD=$(wc -w < $1)
# shuffle randome number
NUMRAND=$(shuf -i 1-$NUMWORD -n 1)
echo $NUMRAND
# print random word
RANDWORD=$(cat $1 | awk '{print}' ORS=" " | awk '{print$'$NUMRAND'}')
echo $RANDWORD
fi