如何跳过打开/关闭范围模式的记录?
gawk '/<Lexer>/,/<\/Lexer>/' file
这有效,但它打印第一条和最后一条记录,我想省略。怎么做呢?
它说:“打开范围模式的记录和关闭范围模式的记录都与范围模式匹配。如果不想对这些记录进行操作,可以在规则的操作中编写 if 语句以将它们与您感兴趣的记录。”但没有例子。 我尝试过类似的东西 gawk '/
但它不起作用。 如果您有更好的方法来做到这一点,而不使用 awk,请说出来。
gawk '/<Lexer>/,/<\/Lexer>/' file
this works but it prints the first and last records, which I'd like to omit. How to do so?
It says: "The record that turns on the range pattern and the one that turns it off both match the range pattern. If you don't want to operate on these records, you can write if statements in the rule's action to distinguish them from the records you are interested in." but no example.
I tried something likegawk '/<Lexer>/,/<\/Lexer>/' {1,FNR-1} file
but it doesn't work.
If you have a better way to do this, without using awk, say so.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 2 个单独的匹配语句和一个变量
This matches
并将 p 设置为 1,然后跳到下一行。当 p 为 1 时,它会打印当前行。当它匹配时,它将 p 设置为 0 并跳过。当 p 为 0 时,打印被抑制。
You can do it with 2 separate match statements and a variable
This matches
<Lexer>
and sets p to 1 and then skips to the next line. While p is 1 it prints the current line. When it matches</Lexer>
it sets p to 0 and skips. As p is 0 printing is suppressed.