How to insert a single CR character into a plain text datafile opened in Notepad++ which uses CRLF as record delimiter and LF as end-of-text-line in a notes field?
-
I have a plain text data file that uses the CRLF pair as “end of record” marker and LF character as a line-terminator in its Notes field. I want to open the file in Notepad++ and paste a column-header into the file as the first line, but when I do so, Notepad++ puts a LF as the end-of-line marker. Is there a way to insert a single CR character in front of that LF? I do not want all LF characters to be replaced with CRLF.
-
If I’ve understood correctly, you want it something like this:
…
where line1 is the headers, line 2 is the first record, line 3-5 is the second record with multiple LF , and line 6 is the third record.I accomplished that, when the file is in “Windows (CR LF)” end-of-line mode, by using the ENTER/RETURN key on the keyboard to insert the “end of record” CRLF, and I brought up the Edit > Character Panel to show the “ASCII Codes Insertion Panel”, and I double-click on the LF column of the highlighted row to manually insert the LF instead of a full newline (CR LF).
Alternately, if you are in “Unix (LF)” mode, then ENTER/RETURN will just do the LF character, and you can use the Character Panel and double-click on the CR a few rows down in my screenshot to insert the single CR where you want it.
If you start with a file in CRLF mode, and paste any text into it, it should treat it as CRLF and will translate any lines into CRLF mode. So that’s good for pasting the header line with CRLF line ending… but it’s bad if you want to do mixed, some where you want to paste just LF and some with CRLF.
However, Notepad++ has an often-overlooked feature: Edit > Paste Special > Paste Binary Content: when you use that version of Paste, it won’t do EOL translation on the text you are pasting, so if you had copied something that had mixed LF and CRLF in it, a normal paste would convert them all to CRLF, whereas the Paste Binary Content will keep it mixed.
In my example above, select lines 4-5, including their line endings:
Then move to the end of the file, and paste twice: the first with a normal paste, and the second with a binary paste:
You will see that the line 7-8 paste translated the 4-5 LF into CRLF at the end of 7; but the 9-10 Paste Binary Content kept it as a LF between line 9 and 10.
(I was using View > Show Symbol > Show All Characters throughout these examples, because that’s necessary when trying to figure out line-ending oddities.)
-
Thank you for those tips. They are very useful.