LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-26-2011, 02:00 AM   #1
pjdell
LQ Newbie
 
Registered: May 2011
Posts: 3

Rep: Reputation: Disabled
Downloading all links in an XML file


Hello,

I am, as the forum title suggests, new to linux and to programming and having trouble figuring out how to do this.

I have a very large XML file with a lot of information in it. I'm trying to get a single tag out of the file, each of these tags contains a single web link and I want to download the file at every single one of those links. I really don't know how to do this.

My thought, though its probably not the most efficient or correct way, was to use VIM to search the document and somehow extract all of this one particular tag and then use wget on the links. Really I don't know how to do any of the above or if its even a good solution.

Thanks in advance for help
 
Old 05-26-2011, 02:27 AM   #2
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hello and Welcome to LinuxQuestions,

The rough idea you have can work if you set it up correctly. You could also write your own bash, sed, awk script or any combination of those to perform the task automatically. Have a look at these links to learn about them:
Bash Guide for Beginners
Advanced Bash Scripting Guide
Sed
Awk

You'll have to put in some work of your own if you want to learn. I don't think a lot of users here at LQ will provide you with ready made solutions or copy/paste guides.

Here's one part/indication on how you could get the value in a XML tag from a file and save it into a variable:
Code:
XMLVALUE=$(cat yourfile.xml | grep yourxmltag | sed 's#.*<yourxmltag>\(.*\)<\/yourxmltag>.*#\1#g')
Next you could use the value stored in XMLVALUE with wget.

Have fun with Linux.

Kind regards,

Eric
 
Old 05-26-2011, 08:39 PM   #3
pjdell
LQ Newbie
 
Registered: May 2011
Posts: 3

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by EricTRA View Post
Hello and Welcome to LinuxQuestions,

The rough idea you have can work if you set it up correctly. You could also write your own bash, sed, awk script or any combination of those to perform the task automatically. Have a look at these links to learn about them:
Bash Guide for Beginners
Advanced Bash Scripting Guide
Sed
Awk

You'll have to put in some work of your own if you want to learn. I don't think a lot of users here at LQ will provide you with ready made solutions or copy/paste guides.

Here's one part/indication on how you could get the value in a XML tag from a file and save it into a variable:
Code:
XMLVALUE=$(cat yourfile.xml | grep yourxmltag | sed 's#.*<yourxmltag>\(.*\)<\/yourxmltag>.*#\1#g')
Next you could use the value stored in XMLVALUE with wget.

Have fun with Linux.

Kind regards,

Eric
Awesome thanks, yeah I wasn't looking for a copy/paste I want to actually know wtf i'm doing.
 
Old 05-27-2011, 01:54 AM   #4
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hi,

You're welcome and I'm glad to hear you want to know what you're doing . Now all you have to do is put it together in a script and run it. If you encounter any problems writing and/or executing your script don't hesitate to post. Have fun with Linux.

Kind regards,

Eric
 
  


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
Prompt the user for a file to open, extract the XML and write to another text file. richiep Linux - Newbie 7 10-22-2010 04:34 PM
Help downloading using links Sir Captain General 1 03-04-2009 05:57 AM
Howto forbid anonymous users from downloading files from hot links greeting Programming 13 09-26-2006 01:44 AM
downloading non-absolute links dehuszar Linux - Software 2 08-31-2004 06:52 AM


All times are GMT -5. The time now is 11:55 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration