Hi,
Quote:
Originally Posted by towheedm
druuna,
That's works. I understand the first part to return the URL. To print out only that line I did:
Code:
sed -n 's/DOWNLOAD="\(.*\)"/\1/p' infile
The part to return the file I don't get. I should have mentioned that 'infile' has several URLs, so the second part returns the file part of each URL. How can I get it to return (and print) only the file part of the line starting with DOWNLOAD=". I'm having a hard time understanding the second part. Is it too much to ask for a little explanation?
|
Both my samples assume that
DOWNLOAD="http://ftp.a.b/c/d/file-to-download" is all that's on that line and nothing else. If it isn't then both samples will probably work incorrectly.
Please provide us with a relevant sample, otherwise the answers given might not work.
About my second solution:
Code:
sed 's%.*/\(.*\)"%\1%' infile
- The brown part matches all up to and including the last forward slash,
- The green part matches the rest (minus the last ") and is used in the replace part as \1,
- I used % instead of / as separator because I need to match a forward slash.
The blue part will fail if there's more on a line. Sed is greedy and will grab all up to and including the last / it finds.
Hope this helps.