How to remove every odd line in Notepad++?

You can do it with find and replace:

  • Open the replace dialog (Ctrl + H)
  • Select "Regular expression"
  • Find what: .+\r\n(.+(\r\n|$))
  • Replace with:
    $1
  • Press "Replace All"

Notes:

  • Depending on your OS you need to use \r (old Mac), \n (Unix, OS X) or \r\n (Windows) to match end of line, or just use \R which should work everywhere (thanks for @Aurel Bílý)
  • \n|$ is needed to have correct result even at the end of the file
  • By default, Notepad++ replaces from actual cursor position to the end of file. Make sure to place your cursor to the beginning of file.
    • (You could also check "wrap around", but in that case it will first delete the line your cursor is in, instead of really looking for an odd line.)

Enter image description here


  • Ctrl+H
  • Find what: .+\R(.+)
  • Replace with: $1
  • Replace all

Explanation:

.+      : 1 or more any character but newline
\R      : any kind of linebreak (ie. \r, \n, \r\n)
(       : start group 1
  .+    : 1 or more any character but newline
)       : end group 1
  • Check regular expression
  • DO NOT CHECK . matches newline

Result for given example:

Monkey
Lion
animal

  1. Open the file and put your text cursor at the start of the first line.
  2. Menu → MacroStart Recording
  3. Press the End key on keyboard
  4. Shift + Home, then backspace
  5. Down
  6. Backspace
  7. Down
  8. Menu → MacroStop Recording
  9. Menu → MacroRun a Macro Multiple Times → Tick Run until the end of file
  10. Click Run

Basically perform the action once to remove an odd line, then get the program to repeat the action to the end of the file. This can be used to solve many problems!

Tags:

Notepad++