tags:

views:

41

answers:

3

How to extract "Matthew" from "mtjoseph:6/MKTCzMS/YU.:10974:10060:Matthew"

+5  A: 
echo "mtjoseph:6/MKTCzMS/YU.:10974:10060:Matthew"| awk -F ':' '{print $5}'
eumiro
Googled for *awk split by char*, returned here, oh! my answer is already posted! ;)
takeshin
or `print $NF` to generically take the last field
glenn jackman
A: 

I find echo "mtjoseph:6/MKTCzMS/YU.:10974:10060:Matthew"| cut -d: -f5 simpler.

bobmcn
Someone I highly respect once said "there is a whole generation of programmers who think awk is just a synonym for cut(1)".
jbinto
A: 

Or, just let the shell do it (assuming bash)

entry="mtjoseph:6/MKTCzMS/YU.:10974:10060:Matthew"
name="${entry##*:}"
echo "$name" # ==> Matthew
glenn jackman