$ awk 'BEGIN { while (count++ < 10) string = string"a"; print string; }'
aaaaaaaaaa
$ awk 'BEGIN { while (count++ < 10) print "a"; }'
$ awk 'BEGIN { count = 1;
> do
> print "ouput at least once";
> while (count != 1) }'
ouput at least once
$ cat score.txt
beyes 10000 90 78 98
admin 10001 99 64 72
tony 10002 45 32 56
tom 10003 12 34 87
lilei 10004 48 25 70
$ awk '{ for (i = 1; i <= NF; i++) total = total + i; } END {print total}' score.txt
75
$ awk 'BEGIN { ORS=""; } { for (i = NF; i > 0; i--) print $i, " "; print "\n"; }' score.txt
98 78 90 10000 beyes
72 64 99 10001 admin
56 32 45 10002 tony
87 34 12 10003 tom
70 25 48 10004 lilei
$ awk 'BEGIN {count = 1; while(1) {
> print "Loop...";
> if (count == 5)
> break;
> count++;
> }}'
Loop...
Loop...
Loop...
Loop...
Loop...
$ cat continue.awk
BEGIN {
count = 1;
while ( count <= 8) {
if ( count >= 5) {
count++;
continue;
}
print "Value of count", count;
count++;
}
}
$ awk -f continue.awk
Value of count 1
Value of count 2
Value of count 3
Value of count 4
$ cat exit.awk
BEGIN {
count = 1;
while (count <= 8) {
if (count == 5) {
exit;
}
print "Value of count", count;
count++;
}
}
$ awk -f exit.awk
Value of count 1
Value of count 2
Value of count 3
Value of count 4
欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) | Powered by Discuz! X3.2 |