Dealing with Newline Issues on Text Files: Examples and Reference
Last updated:Table of Contents
- Windows-style to unix-style newline
- Replace CR LF with LF
- Replace \r\n with \n
- Open file in hexadecimal mode
Style | Name | Character | Hexcode | Decimal |
---|---|---|---|---|
Windows-style | CR LF | \r\n | OxD 0xA | 13 10 |
Unix-style | LF | \n | 0xA | 10 |
Windows-style to unix-style newline
In other words, convert \r\n
to \n
.
Use sed:
$ sed ':a;N;$!ba;s/\r\n/\n/g' windows-newlines.txt > out.txt
Replace CR LF with LF
See above: Windows-style to unix-style newline
Replace \r\n with \n
See above: Windows-style to unix-style newline
Open file in hexadecimal mode
Use hexedit. You can also edit the file directly.
Using hexedit to view and edit a text file.
Hex codes in orange area and the
equivalent text in blue
Hex codes in orange area and the
equivalent text in blue
References
- Vim Hexcode table http://vimdoc.sourceforge.net/htmldoc/digraph.html#digraph-table