我必须在输入文件中每次出现表达式AAA"后打印 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' fileb) 在某种模式后打印所有记录:
b) Print all records after some pattern:
awk 'f;/pattern/{f=1}' filec) 在某种模式后打印第 N 条记录:
c) Print the Nth record after some pattern:
awk 'c&&!--c;/pattern/{c=N}' filed) 在某种模式后打印除第 N 条记录以外的所有记录:
d) Print every record except the Nth record after some pattern:
awk 'c&&!--c{next}/pattern/{c=N}1' filee) 在某种模式后打印 N 条记录:
e) Print the N records after some pattern:
awk 'c&&c--;/pattern/{c=N}' filef) 在某种模式后打印除 N 条记录以外的所有记录:
f) Print every record except the N records after some pattern:
awk 'c&&c--{next}/pattern/{c=N}1' fileg) 从某种模式打印 N 条记录:
g) Print the N records from some pattern:
awk '/pattern/{c=N}c&&c--' file我将变量名称从找到"的f"更改为计数"的c",其中更合适,因为这更能表达变量的实际含义.
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更多推荐
匹配模式后打印特定行数
发布评论