使用 sed 抓取字符串 [英] Use sed to grab a string
本文介绍了使用 sed 抓取字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 curl 从站点获取 html,然后我只需要一个特定的字符串,它介于 'standards.xml?revision=' 和 '&' 之间.我正在使用 sed 来执行此操作,但我似乎无法正确使用正则表达式,需要一些帮助.
I'm using curl to get the html from a site then I just need a specific string which is between 'standards.xml?revision=' and '&'. I'm using sed to do this but I can't seem to get the regex right and needed some help.
curl website.com | sed -r 's|.*standards\.xml\?revision=([0-9]+).*|\1|'
我得到的输出是完整的 html——任何帮助将不胜感激.
The output I'm getting is the full html--any help would be appreciated.
推荐答案
大功告成.尝试使用 -n
选项和 sed
不打印不匹配的数据并将 p
修饰符添加到 s|||
到打印替换字符串
You're almost there. Try using -n
option with sed
not to print unmatched data and add p
modifier to s|||
to print replace string
curl website.com | sed -n -r 's|.*standards\.xml\?revision=([0-9]+).*|\1|p'
这篇关于使用 sed 抓取字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文