

This is the important part in this regex, a row is only matched (and removed), when there is exactly the same row following somewhere else in the file. (?=.*^\1$) this is a positive lookahead assertion. \s+?^ this part matches all whitespace characters (newlines!) till the start of the next row => This removes the newlines after the matched row, so that no empty row is there after the replacement. The matched row is stored, because of the brackets around and accessible using \1 (.*?) matches any characters 0 or more times, but as few as possible (It matches exactly on row, this is needed because of the ". You need to check the options "Regular expression" and ". No sorting is needed for that and the duplicate rows can be anywhere in the file! This leaves from all duplicate rows the last occurrence in the file. Since Notepad++ Version 6 you can use this regex in the search and replace dialogue: ^(.*?)$\s+?^(?=.*^\1$)Īnd replace with nothing. Finally, click "sort lines case sensitive" or "sort lines case insensitive" Next, select a block of text ( Ctrl+ A to select the entire document). Make sure "sort outputs only unique." is checked. The check boxes and buttons required will now appear in the menu under: TextFX -> TextFX Tools. In some cases it may also be called TextFX Characters, but this is the same thing. The TextFX plugin used to be included in older versions of Notepad++, or be possible to add from the menu by going to Plugins -> Plugin Manager -> Show Plugin Manager -> Available tab -> TextFX -> Install. As of Notepad++ version 8.1, there is a specific command to do precisely what this popular question asks. To install the TextFX in the latest release of Notepad++ you need to download it from here: 6.Notepad++ with the TextFX plugin can do this, provided you wanted to sort by line, and remove the duplicate lines at the same time. On the other side, we can freely control the format of the output with the awk command.įor example, let’s put the count after each line: $ awk '' input.txtġ0.00% (1 in 10): I will choose Microsoft Windows.ģ0.00% (3 in 10): I will choose MAC OS. Further, this adds more processes, and the output will be processed more times. If we want to adjust the output, we have to turn to other text processing utilities. sort line with Edit -> Line Operations -> Sort Lines Lexicographically ascending do a Find / Replace: Find What: (.\r )\1+ Replace with: (Nothing, leave empty) Check Regular Expression in the lower left Click Replace All How it works: The sorting puts the duplicates behind each other. However, the format of the output is fixed.
