Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Match (and delete) LF character in Notepad++ regex

Tags:

In Notepadd++ the \r\n regex will find all the CRLF combinations. But I have some lines which end just with LFs. First of all, what is that that? Next, how can I match and delete just that? Neither \r or \n works.

like image 687
1252748 Avatar asked Sep 20 '13 18:09

1252748


People also ask

What is LF character in notepad?

Notepad++ will show all of the characters with newline characters in either the CR and LF format. If it is a Windows EOL encoded file, the newline characters of CR LF will appear (\r\n). If the file is UNIX or Mac EOL encoded, then it will only show LF (\n).

Where can I find LF or CRLF in Notepad++?

In Notepad++ go to the View > Show Symbol menu and select Show End of Line. Once you select View > Show Symbol > Show End of Line you can see the CR LF characters visually. You can then use the menu item Edit > EOL Conversion and select Unix (LF).


2 Answers

LF stands for 'Line Feed'

You can read some more on this answer on serverfault.se:

CR LF means "Carriage Return, Line Feed" - it's a DOS hangover from the olden days from when some devices required a Carriage Return, and some devices required a Line Feed to get a new line, so Microsoft decided to just make a new-line have both characters, so that they would output correctly on all devices.

Windows programs expect their newline format in CRLF (\r\n). *nix expect just LF data (\n). If you open a Unix text document in Notepad on windows, you'll notice that all of the line breaks dissapear and the entire document is on one line. That's because Notepad expects CRLF data, and the Unix document doesn't have the \r character.

There are applications that will convert this for you on a standard *nix distro (dos2unix and unix2dos)

For those wondering, a carriage return and a line feed differ from back in Typewriter days, when a carriage return and a line feed were two different things. One would take you to the beginning of the line (Carriage Return) and a one would move you one row lower, but in the same horizontal location (Line Feed)

Thus, you should be able to replace it with \n.

enter image description here

enter image description here

like image 190
Jerry Avatar answered Sep 21 '22 13:09

Jerry


Using common sense I would suggest following approach:

  1. Replace all the CRLFs with some special string (that you are sure is not present in file), say "fuuuuuu!!!".
  2. Replace LFs with empty string.
  3. Replace all the special strings ("fuuuuuu!!!") back with CRLF.

And you are done.

like image 27
bazinac Avatar answered Sep 24 '22 13:09

bazinac