I'm using curl -s -I -L example.com | grep 'HTTP\|Location'
to track re-directs of a given URL which gives multi-line output.
$ curl -s -I -L google.com | grep 'HTTP\|Location'
HTTP/1.1 301 Moved Permanently
Location: http://www.google.com/
HTTP/1.1 200 OK
I want to concatenate each line of the output and separate it with a semi-colon.
HTTP/1.1 301 Moved Permanently;Location: http://www.google.com/;HTTP/1.1 200 OK;
I've tried curl -s -I -L google.com | grep 'HTTP\|Location' | tr '\n' ';' > file
but this only replaces \n
with ;
and doesn't concatenate the lines.
$ curl -s -I -L google.com | grep 'HTTP\|Location' | tr '\n' ';' > file
$ cat file
HTTP/1.1 301 Moved Permanently;
Location: http://www.google.com/;
HTTP/1.1 200 OK;
Would be grateful for any ideas. Thanks.
The HTTP protocol requires that header lines end with CR LF (\r\n
); you must delete one of them and translate the other to a newline:
$ curl -s -I -L google.com | grep 'HTTP\|Location' | tr -d '\r' | tr '\n' ';'
HTTP/1.1 302 Found;Location: http://www.google.eu/?gws_rd=cr&ei=Hx1JWIDpGordvATO65S4BQ;HTTP/1.1 200 OK;
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments