#将passwd文件每行重复打印10遍;while循环,当i>10时,结束循环。
[root@localhost linshi]# awk '{i=1;while(i<=10){print $0;i++}}' passwd
root:x:0:0:root:/root:/bin/bash
root:x:0:0:root:/root:/bin/bash
root:x:0:0:root:/root:/bin/bash
root:x:0:0:root:/root:/bin/bash
root:x:0:0:root:/root:/bin/bash
root:x:0:0:root:/root:/bin/bash
root:x:0:0:root:/root:/bin/bash
root:x:0:0:root:/root:/bin/bash
root:x:0:0:root:/root:/bin/bash
root:x:0:0:root:/root:/bin/bash
#注释
[root@localhost linshi]# awk -F: '/^root/{i=1;while(i<=NF){print $i;i++}}' passwd
root
x
0
0
root
/root
/bin/bash
#注释
[root@localhost linshi]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.0.170 test
52.87.94.70 registry-1.docker.io
[root@localhost linshi]# awk -F: '{i=1;while(i<=NF){print $i;i++}}' /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.0.170 test
52.87.94.70 registry-1.docker.io
#注释
[root@localhost linshi]# awk -F: '{i=1;while(i<=NF){printf "%-20s", $i;i++};print xxoo}' passwd
[root@localhost linshi]# awk -F: '{i=1;while(i<=NF){printf "%-20s", $i;i++};print }' passwd
awk中的for使用方式