-
Notifications
You must be signed in to change notification settings - Fork 2
/
score.sh
executable file
·56 lines (47 loc) · 1.22 KB
/
score.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
#!/bin/bash
if ! [ -f ~/.matches ]
then
`touch ~/.matches`
fi
if [ "$1" = "-h" ]
then
echo ""
echo "Usage: ./score [options]"
echo " Just calling ./score.sh would show you scores for currently tracked matches"
echo ""
echo " [options]"
echo " -a <cricinfo url> <key> : Track a match"
echo " -r <key> : Stop tracking the match represented by <key>"
echo " -l : Lists currently tracking matches"
echo ""
fi
if [ "$1" = "-a" ]
then
lineCount=`cat ~/.matches | grep -e "|$3" | wc -l | cut -d " " -f8`;
if ! [ "$lineCount" = "0" ]
then
echo "Sorry, that key already exists . Use another key , run ./score -h for more information"
exit 1
fi
echo $2"|"$3 >> ~/.matches
elif [ "$1" = "-r" ]
then
mv ~/.matches matches.old
awk -v rem=$2 'match($1,rem) == 0 {print $0}' matches.old > ~/matches
rm matches.old
elif [ "$1" = "-l" ]
then
cat ~/.matches | while read LINE
do
key=`echo $LINE | cut -d "|" -f2`
value=`echo $LINE | cut -d "|" -f1`
echo $key ":" $value
done
elif [ "$#" = 0 ]
then
cat ~/.matches | while read LINE
do
url=`echo $LINE | cut -d "|" -f1`
curl -s $url | grep -e "<title>" | sed -n 1p | cut -d "|" -f1 | cut -d ">" -f2
done
fi