这是我的超级复杂的awk程序:
#!/usr/bin/awk -f
BEGIN {
count = 0
}
{ if ($1 == "r")
{
nom = $2
ip= $7
numerolinea = NR
}
else {
where = match($0, "Fast")
if (where)
{
count++
printf("\t%5i %20s %15s\n",count,nom,ip)
}
}
}
因此,大家可以看到nom
和ip
的每一个视为字符串有自己的长度。它会是这样输出的摘录:
| 111 cutemyserver1 93.27.255.24 |
| 112 thisisthenamemyserver2 60.231.2.255 |
| 113 anotherlongmyserver3 191.44.192.260 |
| 114 myserver4 173.374.76.183 |
| 115 formyserver5 145.146.321.8 |
| 116 myserver6 64.31.359.70 |
| 117 foofoomyserver7 245.16.19.338 |
正如你也可以看到,count
是一个整数。我的目标是count
对齐为nom
和ip
做的是,正因为如此:
| 8 myserver6 91.580.144.231 |
| 9 narnd 163.11.783.10 |
| 10 erreer 59.194.0.353 |
| 11 111111 178.70.644.91 |
但作弊王氏%5i
不起作用。
感谢
可以打印'count'内E也使用'%5s'或'%-5i' – anubhava 2012-03-02 17:41:57
尝试用'%5d',而不是'%5i' – 2012-03-02 18:07:41