Awk: Difference between revisions
Jump to navigation
Jump to search
Line 12: | Line 12: | ||
=== for === | === for === | ||
<source lang=awk> | <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> | </source> | ||
Line 20: | Line 31: | ||
</source> | </source> | ||
Example | |||
<source lang=awk> | <source lang=awk> | ||
awk ' | awk ' |
Revision as of 14:03, 26 July 2016
Overview
AWK 내용 정리
Options
-F
Delimiter 설정을 바꾼다. 기본값은 ' '(공백)이다. <source lang=bash> $ cat test.txt | awk -F':' '{print $1}' </source>
Statement
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>