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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Truncate a string

Status
Not open for further replies.

BryanY

MIS
Aug 18, 2001
54
US
Basically, I have a file location stored as a string.

Ex: "/export/home/user/data.txt

I would like to remove the filename from the path.

Ex: "/export/home/user"


How would I do that? ("/export/home/user/" is also OK)
 
man dirname

a="/export/home/user"
# the dirname way
echo $(dirname a)
# the ksh way
echo ${a%/*}

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top