shell脚本用于抓取数据,并减去 [英] shell script for grabbing data and subtracting

查看:153
本文介绍了shell脚本用于抓取数据,并减去的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是游戏A和B玩家:

  wget的--output文档=  -  http://runescape.com/title.ws 2  - ;的/ dev / null的\\
    | grep的PlayerCount \\
    |头-1L \\
    | SED的/ ^ [^>] *> //'\\
    | SEDS /当前* / $(日期'+%R%A%D%Y')/\\
    |切-d>中-f 3,4 \\
    | SED的/< \\ / SPAN> //

输出: 111048人下午10时43分54秒2013年2月22日

从游戏B玩家:

|的/ dev / null的; http://oldschool.runescape.com/ 2 - -

  wget的--output文档= grep的人在玩

输出:<!code>目前有42823人打

我要弄清楚有多少玩游戏A,但我不太确定如何把你从这两个输出端得到的数字,并减去他们,这样在相同的格式输出它们:

 `111048人下午10时43分54秒2月22日2013`


解决方案

 #!/ bin / sh的URL1 = HTTP://runescape.com/title.ws
TOT =`wget的-qO- $ URL1 | grep的-i PlayerCount |切-d \\&GT; -f4 |切-d \\&LT; -f1 | SED -e的/,//'`
URL2 = HTTP://oldschool.runescape.com
B =`wget的-qO- $ URL2 | grep的人在玩| AWK'{打印$ 4}'`
一个=`$ expr的TOT - $ B`
回声$ A'的人约会'+%R%A%D%Y'`

...如果你想逗号做这些行添加到脚本...

 出口LC_ALL =的en_US.UTF-8
a_with_comma =`回声$ A | awk的{printf的\\%'D \\ n \\,\\\\ $ 1}`
回声$ a_with_comma人'日期'+%R%A%D%Y'`

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`

解决方案

#!/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'`"

这篇关于shell脚本用于抓取数据,并减去的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆