修剪文本并添加时间戳?
所以基本上我的输出如下:
<span id="PlayerCount">134,015 people currently online</span>
我想要的是一种修剪它以显示的方法:
134,015 - 3:24:20AM - Oct 24
任何人都可以帮忙吗?另请注意,数字可能会发生变化,因此是否可以输出“>”之间的所有内容和当前的“c”?并以某种方式添加时间戳?
在 Linux 中使用终端命令,这就是 bash 对吗?
So basically I have my output as the following:
<span id="PlayerCount">134,015 people currently online</span>
What I want is a way to trim it to show:
134,015 - 3:24:20AM - Oct 24
Can anyone help? Also note the number may change so is it possible output everything between ">" and the "c" in currently? And add a timestamp somehow?
Using commands from terminal in Linux, so that's called bash right?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的意思可能是:
它会生成:
echo
仅用于测试数据。第一个sed
命令会将第一个>
字符之前的所有内容更改为空(即删除它)。第二个将更改从
currently
到行尾的所有内容,并以您想要的格式显示当前日期(尽管我已经添加了年份,因为我对细节有点执着)。这里
date
的相关参数是:格式说明符的完整列表可以从
date
手册页获取(从 shell 执行man date
)。一个小脚本可以从您在评论中提到的页面中为您提供所需的信息:
运行此脚本可以得到:
详细信息:
wget
位会下拉网页并将其写入标准输出。标准错误(进度条)被丢弃。grep
仅提取其中包含单词PlayerCount
的行。head
丢弃除第一个之外的所有内容。sed
剥离到第一个>
字符。sed
将尾随文本更改为当前日期和时间。Do you perhaps mean something like:
which generates:
The
echo
is just for the test data. The firstsed
command will change everything up to the first>
character into nothing (ie, delete it).The second one will change everything from the
currently
to the end of the line with the current date in your desired format (although I have added the year since I'm a bit of a stickler for detail).The relevant arguments for
date
here are:A full list of format specifiers can be obtained from the
date
man page (executeman date
from a shell).A small script which will give you the desired information from the page you mentioned in the comments is:
Running this gives me:
In detail:
wget
bit pulls down the web page and writes it on standard output. The standard error (progress bar) is thrown away.grep
extracts only lines with the wordPlayerCount
in them.head
throws away all but the first of those.sed
strips up to the first>
character.sed
changes the trailing text to the durrent date and time.快速破解(tm):
Quickhack(tm):