Skip to content

Instantly share code, notes, and snippets.

chenjiancan

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>这个手册是我转载的,准备用markdown整理下格式,感觉原来的html太乱了。</p>
<p>TOC是通过python的markdown生成的,<a href="http://www.freewisdom.org/projects/python-markdown/">http://www.freewisdom.org/projects/python-markdown/</a></p>
<pre><code>markdown awk.md &gt; awk.html -x toc
</code></pre>
<p>以下全部内容是从 <a href="http://linuxfire.com.cn/~lily/awk.html">http://linuxfire.com.cn/~lily/awk.html</a> 转载的。</p>
<div id="awktoc">
<div class="toc">
<ul>
<li><a href="#awk">awk 手册</a><ul>
@chenjiancan
chenjiancan / awk_catch_log.sh
Created Aug 20, 2018
监控指定日志文件,要求从在指定时间之后的日志开始扫描,日志中出现 ‘installed memtester’ 行,打印出来
View awk_catch_log.sh
# 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.