Chinaunix
标题:
shell 列操作
[打印本页]
作者:
myeros
时间:
2012-01-17 13:04
标题:
shell 列操作
使用shell如何对一个文件的最后几列打印出来 ,列数不定
作者:
zpc_silenthill
时间:
2012-01-17 13:20
连续列:
awk '{for(i=x;i<NF;++i){printf $i" "}printf $NF"\n"}' filename
作者:
dn833
时间:
2012-01-17 14:31
awk '{print $(NF-1),$NF}'
适用于最后不多的几列
作者:
myeros
时间:
2012-01-17 15:55
么有办法,需要几列写几列了一直减到4
作者:
waker
时间:
2012-01-17 19:58
请读3楼到-4遍
作者:
lionfun
时间:
2012-01-18 00:44
本帖最后由 lionfun 于 2012-01-18 00:48 编辑
我来个
[root@local ~]# cat file.txt
a b c d
d f g h
1 2 3 4 5 6
k j
[root@local ~]# while read line; do set $line; if [ $# -gt 2 ]; then eval "echo \$(($#-1)) \$#";else echo $@; fi; done < file.txt
c d
g h
5 6
k j
复制代码
这个code标签有问题
,两个$不能放在一起:
while read line; do set $line; if [ $# -gt 2 ]; then eval "echo \$$(($#-1)) \$$#";else echo $@; fi; done < file.txt
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2