awk输出匹配行的前一行,后一行的方法

NOCO发布于 分类 Linux

17小时前 有1个用户阅读过

awk输出匹配行的前一行,后一行的方法
# cat test
1
a
2
a
3
4
a
5
6
7
8
a
9

提取a前面一列
# cat test|awk '/a/{print a;}{a=$0}'
1
2
4
8

提取a后面一列
# cat test|awk '/a/{getline;print}'
2
3
5
9

-- The End --

本文标题: awk输出匹配行的前一行,后一行的方法

本文地址: https://seonoco.com/blog/awk-output-matching-line-of-the-previous-line-after-a-line-of-method

本文是否有所帮助?
点赞 0
感谢支持
0
多谢反馈
评论 0
打赏

支持微信/支付宝

评论

网友