由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Unix版 - how to print the last 2 columns of a text file?
相关主题
How to do that using "sort" command?awk里怎么换行?
双面打印awk求助
Help about printing through network!how to print ' in awk and sed.
Re: Print Chinese????Line wrap when printing
Print out Line Number using lp ???A question about awk
Re: how to print out man result?Re: how to print a.ps? help please!
how to let awk not print?Re: How to print chinese in netscape?
How to print landscapely(vs. Portrait) in Wordperfect?how to get rid of the ^M in files?
相关话题的讨论汇总
话题: aaa话题: iej话题: print话题: kdi话题: ien
进入Unix版参与讨论
1 (共1页)
T***B
发帖数: 137
1
001 kdi ien iej ikd mei dig aks aaa ki01
002 kdi ien iej ikd mei aks aaa ki02
003 kdi ien iej ikd mei dig aks aaa ki03
004 kdi ien iej dig aks aaa ki04
I need to retrieve the last 2 columns from a file like above. That is, the
output should be
aaa ki01
aaa ki02
aaa ki03
aaa ki04
Any suggestions? Thanks a lot.
s***e
发帖数: 108
2
Try this!
#!/usr/bin/awk -f
{ if ( NF > 0 ) print $(NF-1) " " $NF }

【在 T***B 的大作中提到】
: 001 kdi ien iej ikd mei dig aks aaa ki01
: 002 kdi ien iej ikd mei aks aaa ki02
: 003 kdi ien iej ikd mei dig aks aaa ki03
: 004 kdi ien iej dig aks aaa ki04
: I need to retrieve the last 2 columns from a file like above. That is, the
: output should be
: aaa ki01
: aaa ki02
: aaa ki03
: aaa ki04

i***e
发帖数: 3219
3
perl -nae 'print "@F[-2,-1]\n"' your_file

【在 T***B 的大作中提到】
: 001 kdi ien iej ikd mei dig aks aaa ki01
: 002 kdi ien iej ikd mei aks aaa ki02
: 003 kdi ien iej ikd mei dig aks aaa ki03
: 004 kdi ien iej dig aks aaa ki04
: I need to retrieve the last 2 columns from a file like above. That is, the
: output should be
: aaa ki01
: aaa ki02
: aaa ki03
: aaa ki04

t********m
发帖数: 54
4
One more example in awk man page
Example 5: Printing Fields in Reverse Order
The following example is an awk script that can be executed
by an awk -f examplescript style command. It prints fields
in reverse order:
{ for (i = NF; i > 0; --i) print $i }
1 (共1页)
进入Unix版参与讨论
相关主题
how to get rid of the ^M in files?Print out Line Number using lp ???
打印问题Re: how to print out man result?
"cal" in unix can print the calendar of this month,how to let awk not print?
format of print-outHow to print landscapely(vs. Portrait) in Wordperfect?
How to do that using "sort" command?awk里怎么换行?
双面打印awk求助
Help about printing through network!how to print ' in awk and sed.
Re: Print Chinese????Line wrap when printing
相关话题的讨论汇总
话题: aaa话题: iej话题: print话题: kdi话题: ien