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 } |