LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 06-08-2004, 01:07 PM   #1
the who
Member
 
Registered: Feb 2004
Location: FRG, EU
Distribution: Slackware current
Posts: 51

Rep: Reputation: 15
Sed, and how to get the file name from an URL


Shell Newbie question. I'm already a little bit experienced with regular expressions due to my work with PHP, but I'm totally stuck with Sed now. :-/

As an example, I have this variable in my shell script:
location="ftp://ftp.bla.com/path/to/a-file.tar.gz"

At a later point in this script I want to get the file name "a-file.tar.gz" from this variable and assign it to a new variable $filename. The regex to get this file name would be [^/]+$

But how do I tell Sed to do this?
 
Old 06-08-2004, 01:55 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
I would probably just use:
echo "ftp://ftp.bla.com/path/to/a-file.tar.gz" | sed 's/.*\///'
 
Old 06-08-2004, 02:20 PM   #3
the who
Member
 
Registered: Feb 2004
Location: FRG, EU
Distribution: Slackware current
Posts: 51

Original Poster
Rep: Reputation: 15
Works. Thanks.
 
  


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 12:46 PM
Mozilla opens URL as local tmp file? phlyersphan Linux - Software 1 11-08-2004 02:24 PM
How do I link a file to a URL site. AZDAVE Linux - Networking 2 10-14-2004 07:30 PM
URL required for samba-common file br_sriram Linux - Software 1 09-18-2004 03:11 PM
Help completing URL file association bmcneely0 Linux - General 0 08-18-2003 05:33 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:01 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration