Reputation: 3325
Players from game A and B:
wget --output-document=- http://runescape.com/title.ws 2>/dev/null \
| grep PlayerCount \
| head -1l \
| sed 's/^[^>]*>//' \
| sed "s/currently.*$/$(date '+%r %b %d %Y')/" \
| cut -d">" -f 3,4 \
| sed 's/<\/span>//'
Output: 111,048 people 10:43:54 PM Feb 22 2013
Players from game B:
wget --output-document=- http://oldschool.runescape.com/ 2>/dev/null | grep "people playing"
Output: There are currently 42823 people playing!
I want to figure how many play Game A, but I am not so sure how to take the numbers you get from both of those outputs, and subtract them and output them in the same format like this:
`111,048 people 10:43:54 PM Feb 22 2013`
Upvotes: 2
Views: 144
Reputation: 10470
#!/bin/sh
URL1=http://runescape.com/title.ws
tot=`wget -qO- $URL1 | grep -i PlayerCount | cut -d\> -f4 | cut -d\< -f1 | sed -e's/,//'`
URL2=http://oldschool.runescape.com
b=`wget -qO- $URL2| grep "people playing" | awk '{print $4}'`
a=`expr $tot - $b`
echo "$a people `date '+%r %b %d %Y'`"
... if you want commas do this add these line to the script ...
export LC_ALL=en_US.UTF-8
a_with_comma=`echo $a | awk "{printf \"%'d\n\", \\$1}"`
echo "$a_with_comma people `date '+%r %b %d %Y'`"
Upvotes: 1
Reputation: 780889
total=$(wget --output-document=- http://runescape.com/title.ws 2>/dev/null |
sed -n '/PlayerCount/{s/^[^0-9]*<span>\([0-9,]*\).*/\1/;s/,//g;p;q;}')
gameb=$(wget --output-document=- http://oldschool.runescape.com/ 2>/dev/null |
sed -n '/people playing/{s/There are currently \([0-9]*\) people playing!/\1/;p;q;}')
gamea=$(($total - $gameb))
Upvotes: 3