Perl 的等价于 awk 的 /text/,/END/ 吗?
我正在寻找替换一个令人讨厌的 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>
I am looking to replace a nasty shell script that uses awk to trim down some HTML. The problem is I cannot find anything in Perl that does the aforementioned function
awk '/<TABLE\ WIDTH\=\"100\%\" BORDER\=1\ CELLSPACING\=0><TR\ class\=\"tabhead\"><TH>State<\/TH>/,/END/'
How can I do this in Perl?
the expected output would be
<TABLE WIDTH="100%" BORDER=1 CELLSPACING=0><TR class="tabhead"><TH>State</TH>
The Perl flipflop operator gives me WAY more. (Everything between the asterisks is junk)
*<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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这会起作用:
expr1 .. expr2
将为 false,直到遇到expr1
为 true 的行。然后它将为 true,直到遇到
expr2
为 true 的行。更新:如果您需要从第一个匹配行的前面修剪掉不匹配的文本,
或者
如果 TEXT 是您只想键入一次的长字符串,那么这将起作用。更改将在进行模式匹配时编辑该行。
I think this will work:
expr1 .. expr2
will be false until it encounters a line whereexpr1
is true.Then it will be true until it encounters a line where
expr2
is true.Update: if you need to trim the non-matching text from the front of the first matching line, this will work
or
if TEXT is a long string that you only want to type once. The change will edit the line while it does the pattern match.
作为一句话(自第一篇文章以来略有变化):
来自 perlrun 手册页:
然后主体的核心是等待开始,然后打印每一行直到结束。
As a one-liner (slightly changed since first post):
From the perlrun man page:
And then the core of the body is to wait for the start, then print every line until the end.