Link to home
Start Free TrialLog in
Avatar of bibi92
bibi92Flag for France

asked on

End of line CRLF (\ r \ n) instead of LF (\ n)

Hello,

How is it possible to replace in file shell linux ?
Thank you

Regards  
End of line CRLF (\ r \ n) instead of LF (\ n)


Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Kent Olsen
Kent Olsen
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of noci
noci

when in a pipeline you can use:  tr -d '\r'
echo -e "\r\n\r\n\r\n" | tr -d '\r' | od -c

Open in new window

Easy approach...

dos2unix file-list-to-fix

Open in new window

I think you are trying to change from LF to CRLF, so
sed -i 's/$/\r/' file_to_change.txt

Open in new window

Much depends on what you are doing and how it is reflected.

\r ^M
cat -v your text file to see what you are dealing
As Kent and David mentioned, dos2unix is the way to do this, and should be part of most unix builds these days.  You can also go the other way, converting <LF> to <CR><LF> via the counterpart command unix2dos.



»bp
I suggested unix2dos on the other question, but bibi92 said they couldn't install extra software. unix2dos is not present by default on Raspberry Pi OS.
you can use python, perl, tr if avalable sed, etc.

cat -v can help confirm what you have and what you want to get rig of.
ctrl-v+key will enter its control character
@bill: Kent Olsen already mentioned dos2unix before, david was the 2nd mention.
@bill: Kent Olsen already mentioned dos2unix before, david was the 2nd mention.
Thanks, I adjusted my prior post.

»bp
SED seems like the simplest approach, have you tried that?

»bp