打印线的具体数量匹配模式之后 [英] print specific number of lines after matching pattern

查看:104
本文介绍了打印线的具体数量匹配模式之后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从输入文件中的前pressionAAA的每次出现后打印81行。我怎么去的?

I have to print 81 lines after each occurrence of the expression "AAA" from my input file. How do I go about that?

推荐答案

下面的成语描述了如何选择给予一定范围的记录
匹配一个特定的模式:

The following idioms describe how to select a range of records given a specific pattern to match:

a)由某种模式打印的所有记录:

a) Print all records from some pattern:

awk '/pattern/{f=1}f' file

二)打印所有记录后,一些模式:

b) Print all records after some pattern:

awk 'f;/pattern/{f=1}' file

C)打印的第N个记录后,一些模式:

c) Print the Nth record after some pattern:

awk 'c&&!--c;/pattern/{c=N}' file

D)打印每条记录后,除了一些模式的第N个记录:

d) Print every record except the Nth record after some pattern:

awk 'c&&!--c{next}/pattern/{c=N}1' file

E)经过一些图案打印N条记录:

e) Print the N records after some pattern:

awk 'c&&c--;/pattern/{c=N}' file

F)打印每条记录后,除了一些模式的N条记录:

f) Print every record except the N records after some pattern:

awk 'c&&c--{next}/pattern/{c=N}1' file

g)因某种模式打印N条记录:

g) Print the N records from some pattern:

awk '/pattern/{c=N}c&&c--' file

我是从F改为变量名的发现,以C为计数,其中
适当因为这是一个什么样的变量实际上是比较前pressive。

I changed the variable name from "f" for "found" to "c" for "count" where appropriate as that's more expressive of what the variable actually IS.

所以,你想要的e上面:

So, you'd want "e" above:

awk 'c&&c--;/AAA/{c=81}' file

这篇关于打印线的具体数量匹配模式之后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆