Hi Everyone,
I have one a.txt:
a b 001 c
b b 002 c
c c, not 002 c
The output should be
001
002
002
If i use cut -f 3 -d' ', this does not work on the 3rd line, so i thought is any way to cut the field counting from the end? or any perl thing can do this?
Thanks
zaxxon
October 27, 2009, 1:54am
2
Use code tags next time please.
awk '{print $(NF-1)}' infile
001
002
002
jimmy_y:
Hi Everyone,
I have one a.txt:
a b 001 c
b b 002 c
c c, not 002 c
The output should be
001
002
002
If i use cut -f 3 -d' ', this does not work on the 3rd line, so i thought is any way to cut the field counting from the end? or any perl thing can do this?
Thanks
I found the solution already, use "reverse split"
daptal
October 27, 2009, 2:05am
4
If you are thinking of using perl then you donot need to use reverse split either
cat abc.txt
a b 001 c
b b 002 c
c c, not 002 c
~$ cat abc.txt | perl -e 'while(<>){ my @cols = split; print "$cols[-2]\n";}'
001
002
002
HTH,
PL