Convert cURL multi-line output to single, semi-colon-separated line

tech-otaku

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.

AlexP

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.

edited at
0

Comments

0 comments
Login to comment

Related

Why am I seeing multi line standard output for what should be a single line writer?

How to match both multi line and single line

convert multi line string to single line

Write multi-line statement on single line

BATCH - How to get only a single line from a multi-line command output

How to make output to a single line from multi line. Can we do it using generators as well?

JAVA: multi-line input and separated by spaces

Convert single line RSA private ssh key to multi line

Replacing the first space in each line with semi-colon on a file editor

Convert multi-line if statment to single line with map

read the last line of multi-line string separated by line feeds

R- start a new line after a semi colon?

rails: how would you convert a multi-line output into html?

Display matrix with single line semi-colon delimited format

When to terminate a line in JQuery with the semi-colon ; character

Convert multilines to single line

Code output in single line?

Convert multi lines to single line with spaces and quotes

Change Multi line strings to Single line

How to merge multi-line output to form a single line?

Convert this single-line nested for loop to multi-line in python

How to extract colon separated values from the same line?

How can I convert multi-line Python code to a single line?

Replace single line into multi line python

How to convert the output into a single line

How to convert a multiple line input into single/multiple line output | BASH

How Can I Use Data Validation On Single or Multiple Email Addresses That are Semi-colon Separated?

Jenkins convert multi line variable to single line

Bash: Commands to Convert Multi Lines to Single Line