in reply to One Liner to strip crlf

Is the requirement that the \r shall be in front of a \n or should all \r'r be stripped even if the first line (my interpretation of "header") contains a \r anywhere, like in

123,"abc\rdef",4,\n

Beside that, we probably like the *reason* fro the strip needage to be able to come up with better answers.


Enjoy, Have FUN! H.Merijn

Replies are listed 'Best First'.
Re^2: One Liner to strip crlf
by dirtdog (Monk) on Sep 04, 2014 at 16:01 UTC

    Hi, To clarify. I'm trying to create a one-liner that looks at the first line only to see if it has a CRLF, and if it does, then go ahead and execute the search and replace on all lines. The search and replace command works. The piece i can't figure out is how to check if a condition exists on the 1st line only and if it does...then execute the command on the entire file in a one-liner.

      Something like this?

      perl -pi -0e'm/\A[^\n]*\r\n/ and s/\r\n/\n/g' file

      Enjoy, Have FUN! H.Merijn