用 sed 获取两个字符串之间的值?
我在一行中有以下数据:
<a href="#page-metadata-start" class="assistive">Go to start of metadata</a>
<div id="page-metadata-end" class="assistive"></div>
<fieldset class="hidden parameters">
<input type="hidden" title="browsePageTreeMode" value="view">
</fieldset>
<div class="wiki-content">
<p>(openissues)81(/openissues)</p><p>(assignstoday)0(/assignstoday)</p><p>(assignsweek)2(/assignsweek)</p><p>(replyissues)6(/replyissues)</p><p>(wrapissues)26(/wrapissues)</p>
</div>
例如,我想获取“openissues”的值,但我无法弄清楚如何正确检索它。我尝试过的事情之一是以下命令:
sed -n '/(assignstoday)/,/(\/assignstoday)/p' ~/test.txt
有帮助吗?
I have the following data on one line:
<a href="#page-metadata-start" class="assistive">Go to start of metadata</a>
<div id="page-metadata-end" class="assistive"></div>
<fieldset class="hidden parameters">
<input type="hidden" title="browsePageTreeMode" value="view">
</fieldset>
<div class="wiki-content">
<p>(openissues)81(/openissues)</p><p>(assignstoday)0(/assignstoday)</p><p>(assignsweek)2(/assignsweek)</p><p>(replyissues)6(/replyissues)</p><p>(wrapissues)26(/wrapissues)</p>
</div>
I'd like to grab the value for "openissues" for example, but I can't figure out to properly retrieve this. One of the things I tried is the following command:
sed -n '/(assignstoday)/,/(\/assignstoday)/p' ~/test.txt
Any help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一个可能满足您编辑要求的快速技巧:
但是在解析 HTML 时,正则表达式确实不是正确的方法。
a quick hack to possibly meet your edited requirement:
but regexes are really not the way to go when parsing HTML.
我会尝试
用该内容替换除您正在搜索的内容之外的所有内容。
编辑:现在我看到尼尔的答案,几乎是一样的,接受他的。我留下我的答案来定制您想要提取的值。
I'd try
that is, replace everything except the contents of what you are searching, with that content.
edit: Now I see Neil's answer, that's practically the same, accept his. I leave my answer for the customization of which value you want to extract.