Search notes:

Line break

A line break in DOS/Windows text files consists of a CR followed by a LF.
In Unix text files, it only consists of a LF.
On MACs prior to MAC OS X, it was a CR. With/since MAC OS X, they use Unix endings, too.

CR

Carriage return: \x0D or \r.

LF

Line feed: \x0A or \n.

Changing line endings

dos2unix

The Linux Linux shell command dos2unix changes DOS line endings in a file to UNIX endings.

PowerShell

In PowerShell, line endings might be changed with something like
[IO.File]::WriteAllText(
   "$pwd\file.unix",
   [IO.File]::ReadAllText("$pwd\file.dos") -replace ("`r`n", "`n")
)
Text that contains Unix and DOS endings might be converted to text that contains DOS endings only like so
$txt_mixed = "@$([char]0x0a)@$([char]0x0d)$([char]0x0a)@"
$txt_dos    = $txt_mixed -replace "(?<!`r)`n", "`r`n"

# verify result:
$text_dos | format-hex
…
…   40 0D 0A 40 0D 0A 40

See also

show-newline.pl is a Perl script that shows line endings in a file.
dos-or-unix.pl is another Perl script that tries to determine if a file has DOS or Unix line endings.
In .NET, the value for the line break that is used on the current platform can be queried with System.Environment.NewLine.
The Perl function chomp() removes trailing new lines in variables that contain lines of text.
The functionality of chomp() can be imitated in Python with str.rstrip('\n\r').
In Python, a string containing line breaks can be split into its lines using the method str.splitlines().
The VIM options endofline and fixendofline.
The Visual Basic for Applications constant that signifies a line break is vbCrLf.
git config --global core.autocrlf false
The notepad++ menus Settings -> Preferences -> New Document and Edit -> EOL Conversion
The number of line breaks in a file can be counted with the shell utility wc.

Index