Re: cut



On 2006-10-28, virus.clear.net.nz wrote:
If I have a listing of packages,
such as : -

XML-Parser-2.34.tbz2
bin86-0.16.17.tbz2
libxml2-2.6.26.tbz2
system-tools-backends-1.4.2.tbz2

I want to cut the version number from the listing, leaving only bin86,
libxml2, etc.
I think that cutting a "-" followed by a {0-9} achieve this ??? but cut
only allows for a single delimiter.

How to achieve this ?

If you have the name in a variable:

pkg=bin86-0.16.17.tbz2
echo ${pkg%-[0-9]*}


If it's in a file or other list, pipe it through sed:

sed 's/\(.*\)-[0-9].*/\1/'

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
.



Relevant Pages

  • Re: cut
    ... I want to cut the version number from the listing, leaving only bin86, libxml2, etc. ...
    (comp.unix.shell)
  • Re: cut
    ... I want to cut the version number from the listing, leaving only bin86, libxml2, etc. ... I think that cutting a "-" followed by a achieve this ??? ...
    (comp.unix.shell)
  • Re: cut
    ... I want to cut the version number from the listing, leaving only bin86, libxml2, etc. ... I think that cutting a "-" followed by a achieve this ??? ...
    (comp.unix.shell)
  • Re: WJF video: Vova balls
    ... because his exclusion is humourously insulting, i.e. listing a bunch of people and saying they look pretty and then leaving someone out... ...
    (rec.juggling)
  • Re: Tired of fake keywords in title - get revenge
    ... pack a lunch before you attempt to read that listing. ... Dude has 775 fb's with a 99.2% and he threatens about leaving fb? ...
    (alt.marketing.online.ebay)