I have a big text file containing a million lines. I would like to find identical lines that match my specific text and leave the first occurrence intact. Any ideas?
So the algorithm should roughly be as follows:
For all lines in text file
Find duplicate lines
If duplicated line contains our text
Remove all these lines except the first one
For example, we are looking for the duplicated lines with text “Word”.
Example of the file:
Test1 Test2 Test3 Test4 Test5
Test1 Test2 Test3 Test4 Test5
Word1 Word2 Word3 Word4 Word5
Test1 Test2 Test3 Test4 Test5
Word1 Word2 Word3 Word4 Word5
The output file:
Test1 Test2 Test3 Test4 Test5
Test1 Test2 Test3 Test4 Test5
Word1 Word2 Word3 Word4 Word5
Test1 Test2 Test3 Test4 Test5
grep PATTERN | uniq
, with the caveats that non-matches are also printed, only pattern matches are passed touniq
, and order is preserved? – l0b0 Jan 13 at 7:03