LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Grab Filename on the end of a (Download) URL (http://www.linuxquestions.org/questions/programming-9/grab-filename-on-the-end-of-a-download-url-388458/)

hitman_et 12-01-2005 08:02 PM

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

schneidz 12-01-2005 08:11 PM

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

chrism01 12-01-2005 09:38 PM

Code:

t='ftp://name/name2/file.ext'
basename $t

outputs: file.ext

hitman_et 12-02-2005 04:52 AM

Thanks both worked a treat


All times are GMT -5. The time now is 09:44 PM.