Is there a way for curl to append output to an existing file using --output/-o option without overwriting it? I cannot use redirection:
curl http://url >> file
Because I am using a return code from curl:
response="$(curl --write-out "%{http_code}" --silent --output file http://url)"
Use the shell's appending output redirection ( >> ) rather than curl's --output option.
For those of you want to copy the cURL output in the clipboard instead of outputting to a file, you can use pbcopy by using the pipe | after the cURL command. Example: curl https://www.google.com/robots.txt | pbcopy . This will copy all the content from the given URL to your clipboard.
Append to a File using the Redirection Operator ( >> ) Redirection allows you to capture the output from a command and send it as input to another command or file. The >> redirection operator appends the output to a given file.
You can use cat with redirection to append a file to another file. You do this by using the append redirection symbol, ``>>''. To append one file to the end of another, type cat, the file you want to append, then >>, then the file you want to append to, and press <Enter>.
Give process substitution a try.
curl --output >(cat >> file) http://url
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With