- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- quick one: cut'ing or seding directory path to get...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2001 02:28 AM
10-18-2001 02:28 AM
If I have a variable $F
that looks something like the following:
/usr/bin/dothis.ksh
and or
/usr/contrib/bin/dothat.ksh
what's the best way to extract the filename
echo $F | nice -and -sweet
Thanks!
Bill
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2001 02:32 AM
10-18-2001 02:32 AM
Re: quick one: cut'ing or seding directory path to get just the filename
-Santosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2001 02:34 AM
10-18-2001 02:34 AM
SolutionFILENAME=$(basename $F)
not sure if this is a requirement, but you can also strip of the suffix,i.e.:
if $F=/usr/contrib/bin/something.ksh
FILENAME=$(basename $F .ksh)
$FILENAME should be set to the word something.
-Santosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2001 02:40 AM
10-18-2001 02:40 AM
Re: quick one: cut'ing or seding directory path to get just the filename
That was just what I was looking for..
It would have saved me so much pain if I knew about that around a year ago!!
Thanks again,
Bill
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2001 02:43 AM
10-18-2001 02:43 AM
Re: quick one: cut'ing or seding directory path to get just the filename
Also just FYI, you can use the dirname command to get the directory part of the full path. Its complimentary to the basename command.
-Santosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2001 02:49 AM
10-18-2001 02:49 AM
Re: quick one: cut'ing or seding directory path to get just the filename
something I learned yesterday from this forum:
This solution will not cover filenames with blanks! Enclose $F in double quotes !
# echo $F
/tmp/a b c
# FILENAME=$(basename "$F")
# echo $FILENAME
a b c
#
Volker
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2001 03:48 AM
10-18-2001 03:48 AM
Re: quick one: cut'ing or seding directory path to get just the filename
NewPath=${F##*/}
(Essentially NewPath = $F but remove the largest section from the front of F which matches the glob '*/')
dave
(shell should be efficient :-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2001 11:36 AM
10-18-2001 11:36 AM
Re: quick one: cut'ing or seding directory path to get just the filename
LIST=`echo "$1" | sed 's#/# #g' `
for I in $LIST
do
LASTI=$I
done
echo $LASTI
Where $1 is your fullpath'd file /a/b/c/file1
.....or as said above: basename $1