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

LinuxShell Scripting

Avatar of undefined
Last Comment
Bill Prew
ASKER CERTIFIED SOLUTION
Avatar of Kent Olsen
Kent Olsen
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
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

Avatar of David Favor
David Favor
Flag of United States of America image

Easy approach...

dos2unix file-list-to-fix

Open in new window

Avatar of simon3270
simon3270
Flag of United Kingdom of Great Britain and Northern Ireland image

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

Open in new window

Avatar of arnold
arnold
Flag of United States of America image

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
Avatar of Bill Prew
Bill Prew

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
Avatar of simon3270
simon3270
Flag of United Kingdom of Great Britain and Northern Ireland image

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.
Avatar of arnold
arnold
Flag of United States of America image

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
Avatar of noci
noci

@bill: Kent Olsen already mentioned dos2unix before, david was the 2nd mention.
Avatar of Bill Prew
Bill Prew

@bill: Kent Olsen already mentioned dos2unix before, david was the 2nd mention.
Thanks, I adjusted my prior post.

»bp
Avatar of Bill Prew
Bill Prew

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

»bp
Linux
Linux

Linux is a UNIX-like open source operating system with hundreds of distinct distributions, including: Fedora, openSUSE, Ubuntu, Debian, Slackware, Gentoo, CentOS, and Arch Linux. Linux is generally associated with web and database servers, but has become popular in many niche industries and applications.

71K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo