LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Variables in moving / renaming files using CURL to download (https://www.linuxquestions.org/questions/linux-software-2/variables-in-moving-renaming-files-using-curl-to-download-829165/)

Freaksta 08-29-2010 01:17 PM

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

Freaksta 08-29-2010 01:20 PM

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?

Kenhelm 08-29-2010 02:59 PM

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.

Freaksta 08-30-2010 09:13 AM

Quote:

Originally Posted by Kenhelm (Post 4081642)
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.

:(


All times are GMT -5. The time now is 02:59 PM.