Awk: Difference between revisions
Jump to navigation
Jump to search
(Created page with "== Overview == AWK 내용 정리 category:programming") |
|||
(8 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
== Overview == | == Overview == | ||
AWK 내용 정리 | AWK 내용 정리 | ||
== Options == | |||
=== -F === | |||
Delimiter 설정을 바꾼다. 기본값은 ' '(공백)이다. | |||
<source lang=bash> | |||
$ cat test.txt | awk -F':' '{print $1}' | |||
</source> | |||
== Statement == | |||
=== if === | |||
<source lang=awk> | |||
if (conditional-expression) | |||
{ | |||
action1; | |||
action2; | |||
} | |||
</source> | |||
=== for === | |||
<source lang=awk> | |||
for (initialization; condition; increment) | |||
body | |||
</source> | |||
Example | |||
<source lang=awk> | |||
awk ' | |||
{ | |||
for (i = 1; i <= 3; i++) | |||
print $i | |||
}' inventory-shipped | |||
</source> | |||
=== while === | |||
<source lang=awk> | |||
while (condition) | |||
body | |||
</source> | |||
Example | |||
<source lang=awk> | |||
awk ' | |||
{ | |||
i = 1; | |||
while (i <= 3) { | |||
print $i; | |||
i++; | |||
} | |||
}' inventory-shipped | |||
</source> | |||
== Builtin variables == | |||
=== NR === | |||
지정된 숫자만큼 입력된 라인을 스킵한다. | |||
<source lang=awk> | |||
$ sudo asterisk -rx "core show taskprocessors" | awk 'NR>2 {if ($3 > 100) {print $1}}' | |||
</source> | |||
== See also == | |||
* https://www.gnu.org/software/gawk/manual/html_node/index.html - The GNU Awk User’s Guide | |||
[[category:programming]] | [[category:programming]] |
Latest revision as of 10:21, 5 June 2019
Overview
AWK 내용 정리
Options
-F
Delimiter 설정을 바꾼다. 기본값은 ' '(공백)이다. <source lang=bash> $ cat test.txt | awk -F':' '{print $1}' </source>
Statement
if
<source lang=awk> if (conditional-expression) { action1; action2; } </source>
for
<source lang=awk> for (initialization; condition; increment)
body
</source>
Example <source lang=awk> awk ' {
for (i = 1; i <= 3; i++) print $i
}' inventory-shipped </source>
while
<source lang=awk> while (condition)
body
</source>
Example <source lang=awk> awk ' {
i = 1; while (i <= 3) { print $i; i++; }
}' inventory-shipped </source>
Builtin variables
NR
지정된 숫자만큼 입력된 라인을 스킵한다.
<source lang=awk> $ sudo asterisk -rx "core show taskprocessors" | awk 'NR>2 {if ($3 > 100) {print $1}}' </source>
See also
- https://www.gnu.org/software/gawk/manual/html_node/index.html - The GNU Awk User’s Guide