nabasoki
nabasoki

Reputation: 57

How can i remove duplicated lines (txt file)?

today I was trying to remove duplicate lines on a simple text file, something like:

input (list.txt):

hello
hello
try

output (list.txt):
try

i was trying with notepad++ to remove duplicate rows and remove the remaining one but nothing. is there a software o some function for do this with notepad++?

thanks.

Upvotes: 2

Views: 10112

Answers (2)

Toto
Toto

Reputation: 91385

Assuming the file is sorted, to have all duplicate lines together.

  • Ctrl+H
  • Find what: ^(.+(?:\R|$))\1+
  • Replace with: LEAVE EMPTY
  • check Wrap around
  • check Regular expression
  • DO NOT CHECK . matches newline
  • Replace all

Explanation:

^           : beginning of line
  (         : start group 1
    .+      : 1 or more any character but newline
    (?:     : start non capture group
      \R    : any kind of linebreak
     |      : OR
      $     : end of line
    )       : end group
  )         : end group 1
  \1+       : back-reference to group 1, may appear 1 or more times

Result for given example:

try

Upvotes: 9

Matthew Lagerwey
Matthew Lagerwey

Reputation: 120

you can do it with php by exploding each line to an array then using the array_unique to get rid of duplicate values then implode the array using \n as a seperator. It can be done in php with 6 lines of code or less readfile explode file unique_array file implode file write file close file return file

Upvotes: 0

Related Questions