Skip to main content

CRLF to LF Converter

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:

In Linux or macOS:

  1. Using the dos2unix command:

    • Open a terminal window.

    • Navigate to the directory containing the file you want to convert.

    • 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 {} \;
  2. Using the sed command:

    • Open a terminal window.

    • Navigate to the directory containing the file you want to convert.

    • 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.

In Windows:

  1. Using Notepad++:

    • Open the file you want to convert in Notepad++.
    • Click the "Search" menu and select "Replace".
    • In the "Find what" field, enter \r\n.
    • In the "Replace with" field, enter \n.
    • Click the "Replace All" button.

    This will replace all occurrences of CRLF with LF in the file.

  2. 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.
  3. 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.
tip

Remember to back up your files before making any changes.