If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Extracting the name out of a file name..

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-01-03, 17:02
phud phud is offline
Registered User
 
Join Date: Oct 2003
Posts: 11
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?
Reply With Quote
  #2 (permalink)  
Old 10-02-03, 04:19
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
Join Date: Jun 2002
Location: UK
Posts: 525
This looks familiar ;-)

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

Damian
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On