Skip to content

Instantly share code, notes, and snippets.


Block or report user

Report or block chenjiancan

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View awk.html
<p>TOC是通过python的markdown生成的,<a href=""></a></p>
<pre><code>markdown &gt; awk.html -x toc
<p>以下全部内容是从 <a href=""></a> 转载的。</p>
<div id="awktoc">
<div class="toc">
<li><a href="#awk">awk 手册</a><ul>
chenjiancan /
Created Aug 20, 2018
监控指定日志文件,要求从在指定时间之后的日志开始扫描,日志中出现 ‘installed memtester’ 行,打印出来
# awk 支持直接比较时间字符串,并通过 ~ match表达式匹配包含字符串
awk '$1>="2018-08-17"&&$2>"09:55:20"&&$0 ~ /installed memtester/ {print $0}' /var/log/dpkg.log
# 输出是: 2018-08-17 09:55:30 status installed memtester:amd64 4.3.0-3
# 如果需要持续监控日志文件,可以使用 tail -1f 持续的输出最后一行,并通过 | pipe 交给awk 处理, exit 表示在匹配到一次后退出
tail -f /var/log/dpkg.log | awk '$1>="2018-08-17"&&$2>"09:55:20"&&$0 ~ /installed memtester/ {print $0; exit}'
# 可通过 tail -Nf (N 为行数)来指定从倒数第几行开始扫描
You can’t perform that action at this time.