Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to append a file with the existing one using CURL?

Tags:

shell

curl

append

I've searched all over the web but couldn't find anything useful for this. Using CURL, I want to append content to a file which is already existing and named as test.pls. Can anyone please tell me how can I do it using curl. The commands I've tried are

curl http://192.99.8.170:8098/stream --output test.pls

curl -K --output test.pls http://192.99.8.170:8098/stream

curl -a  --output test.pls http://192.99.8.170:8098/stream

But all of above starts creating files from scratch.They don't keep the initial content of file Can anyone please help me!

like image 577
MKB Avatar asked Nov 01 '16 11:11

MKB


People also ask

How do you append in curl?

Use the shell's appending output redirection ( >> ) rather than curl's --output option.

How do I redirect a curl output to a file?

Like in: curl http://{one,two}.site.com -o "file_#1. txt" or use several variables like: curl http://{site,host}.host[1-5].com -o "#1_#2" You may use this option as many times as the number of URLs you have. See also the --create-dirs option to create the local directories dynamically.

How do I save a curl script?

cURL commands can download files from a remote location. You can do it in two different ways: -O will save the file in the current working directory with the same file name as remote. -o lets you specify a different file name or location.

Where does curl output go?

Consequentially, the file will be saved in the current working directory. If you want the file saved in a different directory, make sure you change current working directory before you invoke curl with the -O, --remote-name flag! There is no URL decoding done on the file name.


2 Answers

Use the shell's appending output redirection (>>) rather than curl's --output option.

curl http://192.99.8.170:8098/stream >> test.pls
like image 153
Eric Avatar answered Sep 24 '22 17:09

Eric


A much easier and cleaner way is as follows:

curl -sS https://address.to.file.txt >> file-name.txt
like image 28
Ricky Neff Avatar answered Sep 22 '22 17:09

Ricky Neff