比赛A和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>//'
输出:111,048 people 10:43:54 PM Feb 22 2013
比赛B的球员:
wget --output-document=- http://oldschool.runescape.com/ 2>/dev/null | grep "people playing"
输出:There are currently 42823 people playing!
我想知道有多少玩游戏A,但我不太确定如何从这两个输出中获取数字,并减去它们并以相同的格式输出它们:
`111,048 people 10:43:54 PM Feb 22 2013`
答案 0 :(得分:3)
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))
答案 1 :(得分:1)
#!/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'`"
...如果你想要逗号,请将这些行添加到脚本中......
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'`"