How to output first line of curl result in a file with bash script How to output first line of curl result in a file with bash script curl curl

How to output first line of curl result in a file with bash script


Assuming urls.csv is just a simple list of URLs and you're working on a linux system (or any system which has /dev/null), following command will send HEAD requests to each URL and output them next to HTTP response codes.

sed 's/^/url = /; s/\r\?$/\n-o \/dev\/null/' urls.csv |curl -s -K- -w '%{http_code} %{url_effective}\n' -I >outfile

see curl man page for further information.


In reply to your query on outputting the HTTP code, this is given in the second line of the header. You may get this by:

export IFS=$; # This is required to stop everything coming out on one line!curl -i <domain> | head -n 2