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.)
- 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
- Open the file and put your text cursor at the start of the first line.
- Menu → Macro → Start Recording
- Press the End key on keyboard
- Shift + Home, then backspace
- Down
- Backspace
- Down
- Menu → Macro → Stop Recording
- Menu → Macro → Run a Macro Multiple Times → Tick Run until the end of file
- 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!