我希望替换一个讨厌的shell脚本,它使用awk来修剪一些HTML。问题是我在Perl中找不到执行上述功能的任何东西。
awk '/<TABLE\ WIDTH\=\"100\%\" BORDER\=1\ CELLSPACING\=0><TR\ class\=\"tabhead\"><TH>State<\/TH>/,/END/'我如何在Perl中做到这一点?
预期的输出将是
<TABLE WIDTH="100%" BORDER=1 CELLSPACING=0><TR class="tabhead"><TH>State</TH>Perl触发器操作符给了我更多。(星号之间的一切都是垃圾)
*<h2>Browse Monitors (1 out of 497)</h2><br><font size="-1" style="font-weight:normal"> Use the <A HREF=/SiteScope/cgi/go.exe/SiteScope?page=monitorSummary&account=login15 >Monitor Description Report</a> to view current monitor configuration settings.</font>*<TABLE WIDTH="100%" BORDER=1 CELLSPACING=0><TR class="tabhead"><TH>State</TH>发布于 2010-03-27 03:46:12
作为一行代码(自第一篇文章以来略有变化):
perl -n -e '$started = 1 if /<TABLE\ WIDTH\=\"100\%\" BORDER\=1\ CELLSPACING\=0><TR\ class\=\"tabhead\"><TH>State<\/TH>/; next unless $started; print; last if /END/;'从perlrun手册页:
-n causes Perl to assume the following loop around your program, ,这使得它在文件名参数上迭代,有点像sed -n或awk:
行: while (<>) { ... #你的程序转到这里}
然后主体的核心是等待开始,然后打印每一行直到结束。
https://stackoverflow.com/questions/2526161
复制相似问题