LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 12-30-2015, 01:52 PM   #1
ytd_usr
LQ Newbie
 
Registered: Dec 2015
Posts: 3

Rep: Reputation: Disabled
Wink rename as download wget sequentially bash


Greetings. I am a Linux newbie and to this forum.So please go easy on me.
I have txt files in which urls are placed per line. I can download them using wget -i option. But since the links are random, wget puts default names, but after downloading i cant make head or tails of the files. but the urls are of lets say a show's video serially, i.e url1 is for episode1 and so on. since i have many urls, its a pain to rename each using wget's "-o" option. Since i dont know pretty much nothing about bash scripting, could anyone help me? I need wget to read episode 1's url, rename it to show_ep1.
eg. wget -o 'show-ep1' https://show/ep1.mp4 And so on.

Suggestions and modification of this question to support this forums guidelines(if necessary are appericiated)
 
Old 12-30-2015, 03:26 PM   #2
Sefyir
Member
 
Registered: Mar 2015
Distribution: Linux Mint
Posts: 634

Rep: Reputation: 316Reputation: 316Reputation: 316Reputation: 316
use a while loop?

Code:
incr=1; while read i; do wget "$i" -O ep$incr; incr=$((incr+1)); done < txt_file
Code:
incr=1
while read i 
  do 
    wget "$i" -O ep$incr
    incr=$((incr+1))
done < txt_file

Last edited by Sefyir; 12-31-2015 at 04:15 PM. Reason: Wrong flag for naming ep
 
1 members found this post helpful.
Old 12-31-2015, 02:34 AM   #3
ytd_usr
LQ Newbie
 
Registered: Dec 2015
Posts: 3

Original Poster
Rep: Reputation: Disabled
Hello Sefyir. I used your solution and it works,but still names the downloaded files to default url. Below is the output:

Connecting to r1---sn-h557snes.googlevideo.com (r1---sn-h557snes.googlevideo.com)|74.125.169.102|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 78107506 (74M) [video/mp4]
Saving to: XLMWgHCuIX_dSIAzdnHTTHZYr2pqd2VRjrwhPbWn5w=m18

0K .......... .......... .......... .......... .......... 0 94.8K 13m24s
50K .......... .......... .......... .......... .......... 0 28.0K 29m21s

I want "Saving to:XLMWgHCuIX_dSIAzdnHTTHZYr2pqd2VRjrwhPbWn5w=m18 " to be replaced with 'ep1', read next url, rename it as 'ep2' and so on. Is it possible?
And also can you tell me what "i" used in the script. If it is start number, then i am not able to input it.

Last edited by ytd_usr; 12-31-2015 at 02:46 AM.
 
Old 12-31-2015, 05:39 AM   #4
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
ytd_usr, please open a terminal and enter "man wget".
if you have a look at the command line option, you will find one that enables you to define a name for the output file.
it seems sefyir used the wrong option ( -o ).
your task: find the right one.
then the script will work.

about "while read i": it reads the contents of the txt_file line by line, so $i always contains one url.
http://mywiki.wooledge.org/BashGuide/
 
1 members found this post helpful.
Old 12-31-2015, 08:36 AM   #5
ytd_usr
LQ Newbie
 
Registered: Dec 2015
Posts: 3

Original Poster
Rep: Reputation: Disabled
Hello there ondoho. You were right. In Sefyir's "-o" should be "-O". It then works perfectly> Thank You for your input. You both have been of great help . For future users, i will paste the modified script ->

incr=1
while read i
do
wget "$i" -O ep$incr
incr=$((incr+1))
done < txt_file
 
Old 12-31-2015, 10:55 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Please use [code][/code] tags around code to maintain indentation and readability

Your code could be simplified a little too:
Code:
incr=1
while read url
do 
  wget "$url" -O ep$((incr++))
done < txt_file
I renamed 'i' as well to make it a little clearer what is happening
 
Old 12-31-2015, 01:02 PM   #7
Sefyir
Member
 
Registered: Mar 2015
Distribution: Linux Mint
Posts: 634

Rep: Reputation: 316Reputation: 316Reputation: 316Reputation: 316
Yes - I did use the wrong option. I edited mine as well.
 
  


Reply



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
Script To Recursively Enter Subdirectories And Rename Files Sequentially From Scratch padi Linux - Newbie 3 04-25-2015 09:05 AM
Bash Auto Download Script for Podcasts available (wget used) O(V)eGA_l2el) Linux - General 1 01-04-2012 08:15 PM
[SOLVED] rename several files sequentially docaia Programming 4 04-13-2011 04:42 AM
Rename Directories Sequentially (Hexadecimal Format) kiranmannava Linux - Newbie 2 11-17-2009 05:45 PM
mulitple copy a existing directory and rename it at the end sequentially in BASH neo2k Linux - Newbie 2 08-20-2008 10:45 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:00 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