Line feeds turn into space with backticks ! How to fix ?

michaelsanford

Translator, Web Developer
I have a long plain text file whose every line is a complete URL like http://server.com/file_xx.mp3 no spaces or quotes. Each line ends with (what appears with both pico and cat) a newline.

My problem is that I need to use curl (or any other utility you can suggest) to download the files listed in fixed.txt. When I issue cat fixed.txt the file prints just fine with one URL per line. BUT if I issue echo `cat fixed.txt` the newlines get transformed into spaces.

This is problematic because I'm downlading using curl -O `cat fixed.txt` so the first file downloads just fine but the subsequent files are outputted to STDOUT (i.e., binary data printed to the terminal and not to a file).

Should I be using a script to read each subsequent line from fixed.txt to call a new instance of curl, or something ? I'm surprised simply backticking doesn't work !
 
1) Create a script, name it fx. curlGet
--------------------------
#!/bin/bash

while read line
do
`curl -O $line`
done
--------------------

2)
make it executable
chmod +x curlGet

3)
cat fixed.txt | ./curlGet

4)
There is no 4 :)
 
I had been working on a Perl script for a while, with many problems (not least of which being that ctrl-c-ing the script only broke the instance of curl that was running, and it just passed onto the next one).

I changed it a bit to tell me which file it was downloading, but this is perfect and embarassingly simple, thanks! :)

#!/bin/bash

while read line
do
echo $line
`curl -O $line`
done


and called it as
./get.bash < fixed.txt
 
gumse said:
I love Curling, my girlfriend's a Linguist, so helping you out comes naturally :)

That sounds dirty in a very obscure way. Like I'll be sitting in class tomorrow morning and suddenly understand the reference, and everyone will look at my funny when I start snickering.
 
Back
Top