-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathchooseRandom.sh
More file actions
executable file
·53 lines (46 loc) · 923 Bytes
/
chooseRandom.sh
File metadata and controls
executable file
·53 lines (46 loc) · 923 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
function print_usage_and_exit {
echo "Usage: ./chooseRandom.sh"
echo "--src <arg>: path to the source file. Mandatory!"
echo "--trg <arg>: path to the target file. Optional! a file with name '\$source-random' is sused by default"
echo "--max-lines <arg>: the max number of lines to be chosen. 1000 is chosed by default"
exit 1
}
while [[ $# > 1 ]]
do
key="$1"
shift
case $key in
--max-lines)
maxLines=$1
shift
;;
--src)
src=$1
shift
;;
--trg)
trg=$1
shift
;;
*)
# print_usage_and_exit
;;
esac
done
if [ -z "$src" ]
then
echo "source path not specified"
print_usage_and_exit
fi
if [ -z "$trg" ]
then
trg=$src-random
echo "No target path argument was provided. $trg was given by default"
fi
if [ -z "$maxLines" ]
then
maxLines=1000
echo "No max lines was provided. $trg was given by default"
fi
shuf -n $maxLines $src > $trg