Saturday, April 12, 2008

Print last field - grep


$ cat rank.txt
Bash:P:Tue:7
NW:F:Mon:4
DB:P:Tue:8
SE:P:Mon:8

Print the last field. i.e.

Required Output:
---------------
7
4
8
8

Ways:
------
The normal awk way of doing:
$ awk 'BEGIN {FS=":"} {print $NF}' rank.txt

Using sed:
$ sed -n 's/.*://;p' rank.txt

Using grep:
$ grep -o '[^:]*$' rank.txt

1 comment:

Anirudh said...

sed -e 's/.*://'

© Jadu Saikia www.UNIXCL.com