Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2003
    Posts
    11

    Unanswered: Extracting the name out of a file name..

    I'd like to extract the name out of a file name, which is actually a Slackware package file..

    For example:

    $ cd /var/log/packages
    $ ls openss*
    openssh-3.7.1p2-i486-1
    openssl-0.9.7a-i386-2
    openssl-solibs-0.9.7a-i386-2

    Extracting 'openssh' from the first package is easy:

    ls openssh-3.7.1p2-i486-1 | cut -d'-' -f1

    would do it.. but that just doesn't cut it for the last package, which has a dash in it's name..
    Performing the same command on the 'openssl-solibs' would cause the '-solibs' part to be dropped.. which I don't want..

    Anyone got any idea on how to do this?

  2. #2
    Join Date
    Jun 2002
    Location
    UK
    Posts
    525
    This looks familiar ;-)

    sed 's/\(^.*\)-[0-9]\{1,\}\..\{1,\}$/\1/'

    Damian

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •