How to pipe differently the body of the curl answer and the printed output?

Posted by Antoine Lizée on Server Fault See other posts from Server Fault or by Antoine Lizée
Published on 2013-10-25T21:47:14Z Indexed on 2013/10/25 21:56 UTC
Read the original article Hit count: 251

Filed under:

I would like to print in the command line some output of curl, like the http headers, followed by the body of the answer processed by a stdin/stdout program. For instance:

Print the status code: curl -s -w "%{http_code} \\n" -o "/dev/null" http://myURL.com

And then process the output with a json parsing tool: curl -s http://myURL.com | python -mjson.tool

I would like to do both with one command, and I have the feeling that it may be possible thanks to the -o option that makes the difference between the output of curl and the actual answer from the query. The problem is that -o writes directly to a file. Somebody's got a hack?

© Server Fault or respective owner

Related posts about curl