When you share a text file, choose line endings for the program that will read it, not just the computer that will display it. For most files moving between macOS, Linux, and modern development tools, use LF. Choose CRLF when a Windows-specific tool or an established project requires it. On a Mac, you can convert a known text file in Terminal with built-in commands and save the result as a separate file.
What LF and CRLF mean
A line ending is the character or character sequence that marks the end of a line. macOS command-line tools use LF, a single line-feed character. Windows text files commonly use CRLF, a carriage return followed by a line feed. Older classic Mac files may use CR alone, which is a separate, less common format. Apple describes these conventions and notes that CRLF files can cause unexpected behavior in Unix command-line tools because the extra carriage return remains at the end of each line. Apple’s cross-platform scripting guide
As a practical rule, prefer LF for scripts and plain-text files that will be used on macOS, Linux, or in a cross-platform code project, unless the project specifies otherwise. Use CRLF when a receiving application or project explicitly requires it. When you do not know, ask the recipient or check the project’s instructions; the file extension by itself does not tell you which line ending is expected.
Choose the format before converting
First identify the file’s next use. A text file that opens and behaves correctly in the target application may not need conversion. A file that looks normal but fails in a shell script or data-processing step may contain CRLF, leaving hidden carriage returns that affect line matching or field parsing. Apple notes that these issues can arise even when the content appears visually correct. Apple’s explanation of line-ending behavior
TextEdit can create and edit plain-text documents, but Apple’s current guide does not document a control for choosing LF versus CRLF when saving. Its line-break commands format document content; they are not described as a file line-ending selector. If you need to set a specific format, use a text editor with a documented line-ending option or convert a known plain-text file in Terminal. TextEdit User Guide, TextEdit break controls
Convert a known text file in Terminal
Keep the original intact: write the conversion to a different filename, then open or inspect the new file before sharing. In Terminal, change input.txt and output.txt to the actual paths. For a file known to use Windows CRLF that a Mac or Unix tool needs as LF, run:
tr -d '\r' < input.txt > output.txt
This removes carriage returns, leaving LF line endings. For a file known to use LF that the recipient requires as Windows CRLF, run:
CR="$(printf '\r')"
sed "s/$/$CR/" < input.txt > output.txt
This adds a carriage return before each line feed. Apple documents these conversions using tr and sed. Apple’s conversion examples
Use the commands only when you know the source format and the file is plain text. The LF conversion removes every CR character, not just CR characters paired with LF; the reverse conversion assumes the input uses LF. For a mixed file, a legacy CR-only file, or a file with meaningful carriage returns in its content, these simple commands may change more than the line endings you intended. Avoid running them on binary files. If the file’s format is uncertain or preserving encoding and metadata matters, use a suitable editor or conversion tool and check its documentation first.
Check the result and send the right file
Open the output in the intended application and confirm that lines display separately and the file still contains the expected text. Keep the original until the recipient confirms the converted copy works. Send the converted output, not the original, and include the expected line-ending format in your handoff when it matters—for example, “saved with LF line endings.”
The safest choice is the one the receiving tool or project specifies. Without a special requirement, LF is the natural starting point for a Mac workflow; convert to CRLF only when the destination calls for it.
Sources
Designing Scripts for Cross-Platform Deployment — Apple Developer
TextEdit User Guide — Apple Support
Insert line, paragraph, and page breaks in TextEdit on Mac — Apple Support