cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: newline issues

From: Ray Satiro via curl-users <curl-users_at_cool.haxx.se>
Date: Sun, 16 Oct 2016 23:15:55 -0400

On 10/16/2016 1:36 PM, bruce wrote:
> Thanks. Confirms what I saw. Using a headless browser gets the correct
> "\n\r. Is there a way to have curl "substitute" the "\n\r" for the \r
>
> I didn't see anything in my searches. Did I just miss something?

Please don't top post it makes the conversation harder to follow [1].

I don't know why you see \n\r in the headless browser. The content as
it's returned to the browser from the server contains only CRs in that
section, I viewed it in a debugging proxy. Firefox view-source will
treat lone CR as if it's a newline. Chrome it appears ignores them. curl
outputs to stdout exactly as it's received from the server, so you would
have to handle mixed line endings on your own. For example you can use
perl to convert CR/LF/CRLF to LF:

curl --silent --no-verbose ... | perl -pe 's/\r(?!\n)/\n/g; s/\r$//;'

Windows: If you are in the console or in a batch file or something you
will need to use double quotes " instead of single '. Also, some perls
that run in Windows use CRLF translation and some don't, so you'd have
to add binmode(STDIN) for any consistency.

curl --silent --no-verbose ... | perl -pe 'BEGIN {binmode(STDIN);}
s/\r(?!\n)/\n/g; s/\r$//;'

That way you get everything converted to LF in msys and cygwin perl or
to CRLF in strawberry perl, probably others. If you want only LF no
matter what perl is used in Windows add binmode(STDOUT);

[1]: https://curl.haxx.se/mail/etiquette.html#Do_Not_Top_Post

-------------------------------------------------------------------
List admin: https://cool.haxx.se/list/listinfo/curl-users
FAQ: https://curl.haxx.se/docs/faq.html
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2016-10-17