Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Shell 从网页中提取文本并修剪_Shell_Trim - Fatal编程技术网

Shell 从网页中提取文本并修剪

Shell 从网页中提取文本并修剪,shell,trim,Shell,Trim,将输出如下内容: wget --output-document=- http://www.tip.it/runescape/grand-exchange-centre 2>/dev/null \ | grep "The Grand Exchange updated" \ 使用它不是很好,有什么提示吗?您可以编写一个简短的Ruby脚本: gem安装清理 创建一个名为“cleaner.rb”的文件: 然后 wget--output document=-http://www.tip.it/ru

将输出如下内容:

wget --output-document=- http://www.tip.it/runescape/grand-exchange-centre 2>/dev/null \
| grep "The Grand Exchange updated" \

使用它不是很好,有什么提示吗?

您可以编写一个简短的Ruby脚本:

gem安装清理

创建一个名为“cleaner.rb”的文件:

然后

wget--output document=-http://www.tip.it/runescape/grand-exchange-centre 2> /dev/null\
|grep“大交易所更新”|./cleaner.rb


告诉您:“Grand Exchange在1天13小时0分56秒前更新”

如果可以选择使用lynx,您可以免费获得:

#!/usr/bin/env ruby -w
require 'rubygems'
require 'sanitize'

puts Sanitize.clean(gets).trim
如果需要,您可以从中删除前导文本:

$ lynx -dump http://www.tip.it/runescape/grand-exchange-centre | grep "The Grand Exchange updated"
The Grand Exchange updated 1 days, 19 hours, 8 minutes and 48 seconds ago
如果您确实想使用wget并去掉标记,可以使用以下方法:

$ foo="$(lynx -dump http://www.tip.it/runescape/grand-exchange-centre | grep "The Grand Exchange updated")"
$ echo "${foo#*updated }"
1 days, 19 hours, 9 minutes and 8 seconds ago
$wget--output document=-http://www.tip.it/runescape/grand-exchange-centre 2> /dev/null | grep“大交易所已更新”| sed-e's/]\+>///g'-e's/大交易所已更新//”
1天19小时17分2秒前

第一个选项可能是更好的选择。

我在Windows上使用cygwin,还可以安装gem吗?gem到底做什么?
$ lynx -dump http://www.tip.it/runescape/grand-exchange-centre | grep "The Grand Exchange updated"
The Grand Exchange updated 1 days, 19 hours, 8 minutes and 48 seconds ago
$ foo="$(lynx -dump http://www.tip.it/runescape/grand-exchange-centre | grep "The Grand Exchange updated")"
$ echo "${foo#*updated }"
1 days, 19 hours, 9 minutes and 8 seconds ago
$ wget --output-document=- http://www.tip.it/runescape/grand-exchange-centre 2>/dev/null | grep "The Grand Exchange updated" | sed -e 's/<[^>]\+>//g' -e 's/The Grand Exchange updated //'
1 days, 19 hours, 17 minutes and 2 seconds ago