Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

last column or last field of a line

Status
Not open for further replies.

ramana12345

Programmer
Feb 2, 2005
4
0
0
US
Can somebody please suggest me how do I cut the last field of a string

for example I have string

str1/str2/str3/str4/........../strN

I want to get the strN field out of the above string
 
man basename

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
In ksh-like shell:
ColSep="/"
String="str1/str2/str3/str4/........../strN"
LastCol=${String##*$ColSep}
echo "$LastCol"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PHV,

Thankyou very much your solution works,
but unfortunately it is not just a single string I am trying get, it's a column,
can you please suggest me on how to do that for column

in this case the file actually looks like

str1/str2/st3........./strN
word1/word2/word3/.............../wordM
--------------------------------
------------------------ some more lines like this

here M and N may or may not be equal

but I want to grab last field of each line get the output like

strN
wordM
....
....

Thankyou
 
awk -F/ '{print $NF}' /path/to/input

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PHV,

Your solution works great

awk -F/ '{print $NF}' /path/to/input

Thankyou so much
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top