CRLF to LF Converter
- Sukanyeah Krishna
- Jun 11, 2020
- 12,802
Converting CRLF (carriage return + line feed) to LF (line feed) can be accomplished using various methods depending on the operating system and text editor you're using. Here's a summary of common approaches:
Caution
Remember to backup your files before making any changes.
Using the dos2unix command:
Execute the following command:
dos2unix filename.txt
This will convert the line endings in filename.txt from CRLF to LF.
Here is a code that recursively replaces line endings and properly handles whitespace, quotes, and shell meta characters.
find . -type f -exec dos2unix {} \;
Using the sed command:
Execute the following command:
sed -i 's/\r\n/\n/g' filename.txt
This will replace all occurrences of CRLF with LF in filename.txt.
Using Notepad++:
\r\n
\n
Click the "Replace All" button.
This will replace all occurrences of CRLF with LF in the file.
Using a file conversion utility:
There are various file conversion utilities available online that can convert CRLF to LF. You can download and install one of these utilities and follow its instructions to convert the file.
Using a text editor with built-in line ending conversion:
Some text editors, such as Notepad++ and Sublime Text, have built-in options for converting line endings. You can check the documentation of your text editor to see if it supports this feature.