说明awk命令
今天,我正在寻找一个命令的在线模式后,接下来的两行打印和我读到一篇awk命令这我无法理解来了。
Today I was searching for a command online to print next two lines after a pattern and I came across an awk command which I'm unable to understand.
$ /usr/xpg4/bin/awk '_&&_--;/PATTERN/{_=2}' input
有人能解释一下吗?
Can someone explain it?
有人用 _
作为一个变量名时实施共同awk的成语(成语E下面) 。改变每 _
字计数
(或 C
)然后看它是否对你有意义。
Someone used _
as a variable name when implementing a common awk idiom (idiom "e" below). Change every _
to the word count
(or c
) then see if it makes sense to you.
一些背景:下面的成语描述了如何选择一定范围的记录给出了具体的正则表达式匹配:
Some background: The following idioms describe how to select a range of records given a specific regexp to match:
a) Print all records from some regexp:
awk '/regexp/{f=1}f' file
b) Print all records after some regexp:
awk 'f;/regexp/{f=1}' file
c) Print the Nth record after some regexp:
awk 'c&&!--c;/regexp/{c=N}' file
d) Print every record except the Nth record after some regexp:
awk 'c&&!--c{next}/regexp/{c=N}1' file
e) Print the N records after some regexp:
awk 'c&&c--;/regexp/{c=N}' file
f) Print every record except the N records after some regexp:
awk 'c&&c--{next}/regexp/{c=N}1' file
g) Print the N records from some regexp:
awk '/regexp/{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.