LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 12-01-2005, 08:02 PM   #1
hitman_et
Member
 
Registered: Oct 2004
Location: Queensland, Australia
Distribution: Fedora Core 4
Posts: 67

Rep: Reputation: 15
Grab Filename on the end of a (Download) URL


Hi,
I'm trying to work out a script which will get the filename on the end of a download URL.
i.e.
grab 'firefox-1.0.7-1.1.fc4.i386.rpm' from:
ftp://rpmfind.net/linux/fedora/core/updates/4/i386/firefox-1.0.7-1.1.fc4.i386.rpm

So it will need to get everything after the last '/'.

I'm guessing I need a sed or awk command.

Thanks
 
Old 12-01-2005, 08:11 PM   #2
schneidz
Senior Member
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 4,008

Rep: Reputation: 624Reputation: 624Reputation: 624Reputation: 624Reputation: 624Reputation: 624
this should do it:
Code:
echo ftp://rpmfind.net/linux/fedora/core/...1.fc4.i386.rpm | awk -F / '{print $NF}'
hope this helps,

fyi: 'man awk' and 'google: awk last column' helped me get this answer

Last edited by schneidz; 12-01-2005 at 08:12 PM.
 
Old 12-01-2005, 09:38 PM   #3
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,269

Rep: Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028
Code:
t='ftp://name/name2/file.ext'
basename $t
outputs: file.ext
 
Old 12-02-2005, 04:52 AM   #4
hitman_et
Member
 
Registered: Oct 2004
Location: Queensland, Australia
Distribution: Fedora Core 4
Posts: 67

Original Poster
Rep: Reputation: 15
Thanks both worked a treat
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Given a URL how to grab a copy of the file from a command prompt ? Mike Davies Linux - General 2 07-16-2005 11:46 AM
ERROR The requested URL could not be retrieved While trying to retrieve the URL: /re Niceman2005 Linux - General 1 06-29-2005 09:51 AM
Renaming Multiple Files with a "." on the end of the filename dbowles Programming 1 05-09-2005 04:28 PM
XMMS download URLs down. Any url to download it? astitva Linux - Newbie 3 12-28-2003 05:16 AM
ftp download hangs at end jferrod Linux - General 0 04-05-2002 10:14 AM


All times are GMT -5. The time now is 03:30 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration