Carriage Return line feed: CRLF - Linux vs Windows
theBridge2
Posted on June 24, 2023
CRLF? Carriage return (CR) and line feed (LF) come from the days of typewriters.
History
CR = '\r' = 0x0D (HEX) was used to move the cursor to the beginning of the line
LF = '\n' = 0x0A (HEX) was used to move the cursor down to the next line.
The combination of CRLF in type writers is what moved the cursor from the end of the current row to the start of the next row.
Windows vs Linux file compatibility
As computers developed linux moved away from using both CRLF and just used LF to indicate a new line inside a file while windows continued to use both.
If a file has only '\n' (LF) for its line endings then it is linux compatible.
If a file has '\r\n' (CRLF) for its line endings then it is windows compatible.
To convert from linux to windows use the sed command in a linux terminal:
sed -i 's/$/\r/' fileLinux.txt
To convert from windows to linux, use the following command in a linux terminal:
tr -d '\r' <fileWindows.txt > fileLinux.txt
credit: https://www.commandlinewizardry.com/post/removing-windows-line-breaks
How do I know which line ending a file has?
Notepad ++ does it:
VsCode will show you what the line endings are for a given file at the bottom right of the screen.
Posted on June 24, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
November 30, 2024