Perl is unnecessary for this. There is the basename utility:

> basename http://server.com/path/to/sourcefile-2.3.4.tar.bz

yields

sourcefile-2.3.4.tar.bz

or, for the full functionality of the perl script:

> for f in $(cat urls); do basename $f; done
Sources.bz2
Packages.bz2
sourcefile-2.3.4.tar.bz

I prefer this to the perl line-noise incantation :-)

Cheers,
Carl.

On 15/12/05, Matias Rollan <[EMAIL PROTECTED]> wrote:
> On Wed, Dec 14, 2005 at 04:49:59PM +1300, Nick Rout wrote:
> > Now, how do i turn a url like:
> >
> > http://server.com/path/to/sourcefile-2.3.4.tar.bz
> >
> > into just the filename like this:
> >
> > sourcefile-2.3.4.tar.bz
>
> [EMAIL PROTECTED]:~$ cat urls
> http://nz.archive.ubuntu.com/ubuntu/dists/hoary/main/source/Sources.bz2
> http://nz.archive.ubuntu.com/ubuntu/dists/hoary-updates/restricted/binary-i386/Packages.bz2
> http://server.com/path/to/sourcefile-2.3.4.tar.bz
>
> [EMAIL PROTECTED]:~$ cat urls |perl -e 'while(<>){ if($_ =~ /.*\/(.*)$/){ 
> print "$1\n"; } }'
> Sources.bz2
> Packages.bz2
> sourcefile-2.3.4.tar.bz
>
> Cheers,
> --
>   Matías Rollán
>   <[EMAIL PROTECTED]>
>
>

Reply via email to