sed or awk to print 2nd last word

Hi,

I have a file which has the following

/usr/new/xyz/abc
/us1/neb/yxr/def
/usr/bin/cloud1/fgh
/net/bin1/txt1/kdq

I want to do something like this

/usr/new/xyz/abc xyz
/us1/neb/yxr/def yxr
/usr/bin/cloud1/fgh cloud1
/net/bin1/txt1/kdq txt1

I need to add the 2nd last word to the end as shown above

Thnx
Mat

This should work for the input you provided:

awk -F '/' '{ print $0, $(NF-1) }'

The -F option indicates that the slant character is to be used as the word separator. NF is the number of fields (word), so NF-1 is the next to last field. Getting the contents of the next to last field requires the value NF-1 to be dereferenced: $( NF-1 ) .

awk -F \/ '$0=$0 OFS $(NF-1)' infile

Thanks guys, it works. Really appreciate it.