I have a text document that contains a bunch of URLs in this format:
URL = "sitehere.com"
What I'm looking to do is to run curl -K myfile.txt
, and get the output of the response cURL returns, into a file.
How can I do this?
For a single file you can use -O
instead of -o filename
to use the last segment of the URL path as the filename. Example:
curl http://example.com/folder/big-file.iso -O
will save the results to a new file named big-file.iso in the current folder. In this way it works similar to wget but allows you to specify other curl options that are not available when using wget.
There are several options to make curl output to a file
# saves it to myfile.txt
curl http://www.example.com/data.txt -o myfile.txt
# The #1 will get substituted with the url, so the filename contains the url
curl http://www.example.com/data.txt -o "file_#1.txt"
# saves to data.txt, the filename extracted from the URL
curl http://www.example.com/data.txt -O
# saves to filename determined by the Content-Disposition header sent by the server.
curl http://www.example.com/data.txt -O -J
You need to add quotation marks between "URL" -o "file_output" otherwise, curl doesn't recognize the URL or the text file name.
Format
curl "url" -o filename
Example
curl "https://en.wikipedia.org/wiki/Quotation_mark" -o output_file.txt
Example_2
curl "https://en.wikipedia.org/wiki/Quotation_mark" > output_file.txt
Just make sure to add quotation marks.
curl http://{one,two}.example.com -o "file_#1.txt"
curl.haxx.se/docs/manpage.html – onmyway133