how to get the right most word from a Path ? - SCO

This is a discussion on how to get the right most word from a Path ? - SCO ; Hi If I want to cut the filename from a string with random number of folders within the path, how can I accomplish that ? example : FILE=/usr2/tmp/file$$ FILENAME='echo $FILE | cut -d / -?????????' but the path can change: ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: how to get the right most word from a Path ?

  1. how to get the right most word from a Path ?

    Hi

    If I want to cut the filename from a string with random number of
    folders within the path, how can I accomplish that ?

    example : FILE=/usr2/tmp/file$$

    FILENAME='echo $FILE | cut -d / -?????????'

    but the path can change:

    FILE=/usr/reports/mend/2008/1/file$$

    I need to always get the rightmost word after all "/"

    Any clues ?

    thanks



  2. Re: how to get the right most word from a Path ?

    On 2008-08-28, arredondoenrique@gmail.com wrote:
    >
    > If I want to cut the filename from a string with random number of
    > folders within the path, how can I accomplish that ?
    >
    > example : FILE=/usr2/tmp/file$$
    >
    > FILENAME='echo $FILE | cut -d / -?????????'


    > I need to always get the rightmost word after all "/"
    > Any clues ?


    The 'basename' command does that:

    FILENAME="`basename \"$FILE\"`"

    The contorted quotation is needed in case the filename contains
    spaces or other special characters. If not a straight

    FILENAME=`basename $FILE`

    will work. Also see the 'dirname' command that returns the directory
    portion of a path and filename supplied to it.

    --
    Andrew Smallshaw
    andrews@sdf.lonestar.org

  3. Re: how to get the right most word from a Path ?

    On Thu, Aug 28, 2008, arredondoenrique@gmail.com wrote:
    >Hi
    >
    >If I want to cut the filename from a string with random number of
    >folders within the path, how can I accomplish that ?
    >
    >example : FILE=/usr2/tmp/file$$
    >
    > FILENAME='echo $FILE | cut -d / -?????????'
    >
    > but the path can change:
    >
    > FILE=/usr/reports/mend/2008/1/file$$
    >
    >I need to always get the rightmost word after all "/"
    >
    >Any clues ?


    man basename

    fname=`basename $FILE`

    Bill
    --
    INTERNET: bill@celestial.com Bill Campbell; Celestial Software LLC
    URL: http://www.celestial.com/ PO Box 820; 6641 E. Mercer Way
    Voice: (206) 236-1676 Mercer Island, WA 98040-0820
    Fax: (206) 232-9186

    Scientists are explorers. Philosophers are tourists. -- Richard Feynman

  4. Re: how to get the right most word from a Path ?


    ----- Original Message -----
    From:
    Newsgroups: comp.unix.sco.misc
    To:
    Sent: Thursday, August 28, 2008 4:12 PM
    Subject: how to get the right most word from a Path ?


    > Hi
    >
    > If I want to cut the filename from a string with random number of
    > folders within the path, how can I accomplish that ?
    >
    > example : FILE=/usr2/tmp/file$$
    >
    > FILENAME='echo $FILE | cut -d / -?????????'
    >
    > but the path can change:
    >
    > FILE=/usr/reports/mend/2008/1/file$$
    >
    > I need to always get the rightmost word after all "/"
    >
    > Any clues ?


    echo ${FILE##*/}

    --
    Brian K. White brian@aljex.com http://www.myspace.com/KEYofR
    +++++[>+++[>+++++>+++++++<<-]<-]>>+.>.+++++.+++++++.-.[>+<---]>++.
    filePro BBx Linux SCO FreeBSD #callahans Satriani Filk!


+ Reply to Thread