LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 08-29-2010, 01:17 PM   #1
Freaksta
Member
 
Registered: Jan 2003
Distribution: Slackware 9.0
Posts: 174

Rep: Reputation: 30
Variables in moving / renaming files using CURL to download


curl -L http://URL/file[1-2].txt -o $(date +%m-%d-%y)\ newfilename{1,2}.txt

Basically, this command goes to URL, downloads file1.txt and file2.txt, however it saves BOTH files as newfilename1.txt

I would like the script to name the second download (file2.txt) newfilename2.txt

So, before you say to use the -O switch in Curl, please understand that I wish to rename the files so that they are not what they were on the server (names are too long).

so file1.txt becomes newfilename1.txt, file2.txt becomes newfilename2.txt

Is this possible? The command I listed works only until the newfilename{1,2}.txt, it always saves as newfilename1.txt
 
Old 08-29-2010, 01:20 PM   #2
Freaksta
Member
 
Registered: Jan 2003
Distribution: Slackware 9.0
Posts: 174

Original Poster
Rep: Reputation: 30
Or, maybe another way would be to append a number at the end, like with the $(date) command?

Is there a command to add a number to the end of a file based on what files already exist?
 
Old 08-29-2010, 02:59 PM   #3
Kenhelm
Member
 
Registered: Mar 2008
Location: N. W. England
Distribution: Mandriva
Posts: 329

Rep: Reputation: 140Reputation: 140
Try
Code:
curl -L http://URL/file[1-2].txt -o $(date +%m-%d-%y)\ newfilename#1.txt
curl can have back references in the -o option to multiple URLs created by [ ] or { }.
The variable #1 refers to the first [ ] or { } found in the URL.
#2 refers to the second, and so on.
Some examples are given in the -o section of the curl man page.
 
Old 08-30-2010, 09:13 AM   #4
Freaksta
Member
 
Registered: Jan 2003
Distribution: Slackware 9.0
Posts: 174

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by Kenhelm View Post
Try
Code:
curl -L http://URL/file[1-2].txt -o $(date +%m-%d-%y)\ newfilename#1.txt
curl can have back references in the -o option to multiple URLs created by [ ] or { }.
The variable #1 refers to the first [ ] or { } found in the URL.
#2 refers to the second, and so on.
Some examples are given in the -o section of the curl man page.
This works great with one exception:

The first file (#1) is created with 355 bytes.

The second file is created in the correct file size.

 
  


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
Problem Using Variables In CURL bl651 Linux - Newbie 2 07-13-2010 08:31 AM
[SOLVED] cURL Download Files from Manifest doby48 Linux - Software 1 06-22-2010 05:52 PM
AWK script: moving, copying and renaming files uprjamaja Programming 10 12-05-2006 01:06 PM
moving files that have spaces in variables -bash scripting bhar0761 Programming 10 09-22-2005 07:30 AM


All times are GMT -5. The time now is 06:07 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration