|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
How to print the last word in a sentence?
Let say there's a file with many lines and I want to print ONLY the last word in each line. NOTE: I don't know the position of the last word in each line. see examples in below:
I am working He is watching TV She and her mother are not home I need ONE command line to print only the last word in above lines (working, TV and home). Thanks in advance. Thanh |
|
#2
|
|||
|
|||
|
Try:
awk '{ print $NF }' |
|
#3
|
|||
|
|||
|
Perderabo is correct, this is cheaper
sed 's/.* //' |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > How to print the last word in a sentence? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|