2

游戏 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`
4

2 回答 2

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))
于 2013-02-23T04:31:41.310 回答
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'`"
于 2013-02-23T04:35:21.267 回答