image
image

Go Back   macosx.com > Mac Help Forums > Unix & X11

Reply
 
Thread Tools
  #1  
Old February 29th, 2004, 07:08 PM
michaelsanford's Avatar
Psycholinguist
 
Join Date: Oct 2002
Location: Ottawa/Montrιal
Posts: 2,174
Thanks: 0
Thanked 0 Times in 0 Posts
michaelsanford is on a distinguished road
Line feeds turn into space with backticks ! How to fix ?

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 !
__________________
michaelsanford.com • Blog • Twitter • Tumblr • LinkedIn
• iMac Aluminum 24" |
MacOS X 10.5-current | 3.06 GHz Intel Core Duo | 4 GB RAM | 1 TB HDD
• iBook G4 1.42 GHz | MacOS X 10.5-current | 1 GB RAM, 100 GB HDD
• AMD Athlon64 3500+ | Slackware 12 (2.6.21.5-smp) | 2 GB RAM, 2•120 GB RAID 1, 2•500 GB RAID 0
Reply With Quote
  #2  
Old March 1st, 2004, 09:46 AM
gumse's Avatar
Member
 
Join Date: Mar 2001
Location: Sweden
Posts: 403
Thanks: 0
Thanked 0 Times in 0 Posts
gumse is on a distinguished road
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 :-)
__________________
G4 500 MP 1024 MB RAM
LaCie Electron 22" Display
OS X 10.3.9
iMacDV
MacMini
iSight
iPod + iPod Mini
Sony PC100E FireWire Cam
Static IP via a FreeBSD server/gateway
a lot of other Mac's running Macos 7.5 to 9.1 and NetBSD.
A Few Wintel's on the side (I only use them when I get paid by the hour)
Reply With Quote
  #3  
Old March 1st, 2004, 03:46 PM
michaelsanford's Avatar
Psycholinguist
 
Join Date: Oct 2002
Location: Ottawa/Montrιal
Posts: 2,174
Thanks: 0
Thanked 0 Times in 0 Posts
michaelsanford is on a distinguished road
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
__________________
michaelsanford.com • Blog • Twitter • Tumblr • LinkedIn
• iMac Aluminum 24" |
MacOS X 10.5-current | 3.06 GHz Intel Core Duo | 4 GB RAM | 1 TB HDD
• iBook G4 1.42 GHz | MacOS X 10.5-current | 1 GB RAM, 100 GB HDD
• AMD Athlon64 3500+ | Slackware 12 (2.6.21.5-smp) | 2 GB RAM, 2•120 GB RAID 1, 2•500 GB RAID 0
Reply With Quote
  #4  
Old March 1st, 2004, 06:20 PM
gumse's Avatar
Member
 
Join Date: Mar 2001
Location: Sweden
Posts: 403
Thanks: 0
Thanked 0 Times in 0 Posts
gumse is on a distinguished road
I love Curling, my girlfriend's a Linguist, so helping you out comes naturally :-)
__________________
G4 500 MP 1024 MB RAM
LaCie Electron 22" Display
OS X 10.3.9
iMacDV
MacMini
iSight
iPod + iPod Mini
Sony PC100E FireWire Cam
Static IP via a FreeBSD server/gateway
a lot of other Mac's running Macos 7.5 to 9.1 and NetBSD.
A Few Wintel's on the side (I only use them when I get paid by the hour)
Reply With Quote
  #5  
Old March 3rd, 2004, 11:18 AM
scruffy's Avatar
Notorious Olive Counter
 
Join Date: Dec 2000
Location: Soviet Canuckistan
Posts: 1,726
Thanks: 0
Thanked 0 Times in 0 Posts
scruffy is on a distinguished road
Quote:
Originally Posted by gumse
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.
__________________

What is the robbing of a bank compared to the founding of a bank?
-- Bertold Brecht
Reply With Quote
  #6  
Old March 6th, 2004, 12:15 PM
michaelsanford's Avatar
Psycholinguist
 
Join Date: Oct 2002
Location: Ottawa/Montrιal
Posts: 2,174
Thanks: 0
Thanked 0 Times in 0 Posts
michaelsanford is on a distinguished road
:lol:
__________________
michaelsanford.com • Blog • Twitter • Tumblr • LinkedIn
• iMac Aluminum 24" |
MacOS X 10.5-current | 3.06 GHz Intel Core Duo | 4 GB RAM | 1 TB HDD
• iBook G4 1.42 GHz | MacOS X 10.5-current | 1 GB RAM, 100 GB HDD
• AMD Athlon64 3500+ | Slackware 12 (2.6.21.5-smp) | 2 GB RAM, 2•120 GB RAID 1, 2•500 GB RAID 0
Reply With Quote
Reply

Thread Tools

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off
Forum Jump


All times are GMT -5. The time now is 09:00 PM.


Mac Support® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2000-2008 DigitalCrowd, Inc.