|
发表于 2009-8-7 04:06:18
|
显示全部楼层
Post by xiachongbaogc;2013283
[xia@localhost ~]$ cat kk
29241 pts/2 00:00:00 bash
29362 pts/2 00:00:00 ps
[xia@localhost ~]$ head -1 kk | cut -d' ' -f1
29241
测试OK. 而且修改 -f1 to -f2
[xia@localhost ~]$ head -1 kk |cut -d' ' -f2
pts/2
但
[xia@localhost ~]$ head -1 kk |cut -d' ' -f3
没有想象的显示“00:00:00”,是因为 “pts/2” 后空格太多了。 该怎么解决?
是因为空格太多,一个空格算一个filed.
如果空格数固定,容易解决。如果不固定,就只好用类似 ${var##}, ${var%%} 掐头去尾来解决了。 |
|