【发布时间】:2012-12-02 14:04:50
【问题描述】:
我需要删除/过滤一个非常大的日志文件
我设法将日志文件放入以包含<-- 或--> 的行开头的文本块,以包含Content-Length: 的行结尾
现在如果此文本块包含单词REGISTER,则需要将其删除。
我找到了流动的例子:
# sed script to delete a block if /regex/ matches inside it
:t
/start/,/end/ { # For each line between these block markers..
/end/!{ # If we are not at the /end/ marker
$!{ # nor the last line of the file,
N; # add the Next line to the pattern space
bt
} # and branch (loop back) to the :t label.
} # This line matches the /end/ marker.
/regex/d; # If /regex/ matches, delete the block.
} # Otherwise, the block will be printed.
#---end of script---
Russell Davies 在this 页面上撰写
但我不知道如何将其传输到单行语句以在管道中使用
我的目标是将日志文件的tail -F 通过管道传输到最终版本,以便它按分钟获得更新
【问题讨论】:
-
sed 是用于在单行上进行简单替换的出色工具,但对于其他任何事情,您都应该使用 awk,因为将来代码会更清晰并且更容易增强。请发布一些小样本输入和预期输出。