29
8
I am trying to edit a document of 20000 lines. I have to remove every odd line, say for example:
Apple
Monkey
Orange
Lion
fruit
animal
How can I remove every odd line's characters in the document?
29
8
I am trying to edit a document of 20000 lines. I have to remove every odd line, say for example:
Apple
Monkey
Orange
Lion
fruit
animal
How can I remove every odd line's characters in the document?
24
You can do it with find and replace:
.+\r\n(.+(\r\n|$))
$1
Notes:
\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 fileIt almost works, but it is not editing the first set of odd numbered lines, say from 1 to 15. – Nithin N – 2017-09-01T09:42:12.120
Change the screenshot with more transperacy of that replace window. – Biswapriyo – 2017-09-01T10:59:20.650
11Please note that \r
as a line ending is very rare – it was indeed used in Mac OS, but the classic, pre-OS-X versions. In OS X an onwards, line endings are \n
, like any sane Unix. Also \R
is better for matching any line ending. – Aurel Bílý – 2017-09-01T11:33:50.410
@AurelBílý That's true, however Notepad++ only runs on windows, so portability here isn't much of an issue. – Rob – 2017-09-03T01:29:39.477
18
.+\R(.+)
$1
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
. matches newline
Result for given example:
Monkey
Lion
animal
@NithinN: Be aware that accepted answer doesn't work with linux files (ie. linebreak \n
) – Toto – 2017-09-01T10:22:12.043
8
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!
It seems to me this to remove even lines (2,4,6...), not odd ones. – Máté Juhász – 2017-09-01T08:36:06.743
1That is correct. However removing even lines is easier, and the problem can be resolved by adding an empty line at the beginning of the file – Art Gertner – 2017-09-01T08:37:10.157
@ArtGertner should be \r\n.+\r\n replaced with \r\n – chingNotCHing – 2017-09-01T08:42:05.280
@chingNotCHing, good one! I've updated my answer – Art Gertner – 2017-09-01T08:49:31.573
@ArtGertner As you pointed out it works for even lines only. But for large set of data it is not editing for first set of data say from 1-15th line. – Nithin N – 2017-09-01T09:46:08.130
what do you mean by odd line? Do you mean like to remove the odd (unwanted) word from the entire document? – antzshrek – 2017-09-01T08:00:08.947
4Every odd numbered lines like 1,3,5,7,9,11,13,15....so on. – Nithin N – 2017-09-01T08:04:48.863
1Try replace with new line (regexp): [\n.+\n] – Art Gertner – 2017-09-01T08:05:22.143
@ArtGertner i tried with the expression its not working. – Nithin N – 2017-09-01T08:10:10.923
Sorry, I never really use Notepad++, My previous example was tested on Sublime Text. I forgot that its a Windows software. If you are on windows then likely you will need
\n,+\r\n
– Art Gertner – 2017-09-01T08:30:33.4671I d record a stupid macro: down arrow, shift-down arrow, del. – chingNotCHing – 2017-09-01T08:45:30.683
Just out of curiosity, how would a macro detect the end of the document and stop? – Art Gertner – 2017-09-01T08:57:43.643
@ArtGertner the button >> Run until the end of file – chingNotCHing – 2017-09-01T11:22:18.730