Skip to content

Instantly share code, notes, and snippets.

@AnasAboreeda
Last active September 17, 2017 12:03
Show Gist options
  • Save AnasAboreeda/29f54d713722bc28839d51bc9f676bef to your computer and use it in GitHub Desktop.
Save AnasAboreeda/29f54d713722bc28839d51bc9f676bef to your computer and use it in GitHub Desktop.
[Delete duplicated lines]
import sys
import codecs
if (len(sys.argv) < 2):
print('Usage: python3 ./delete_duplicate_lines.py /path/to/target/file')
sys.exit(1)
def uniquelines(lineslist):
unique = {}
result = []
for item in lineslist:
if item.strip() in unique: continue
unique[item.strip()] = 1
result.append(item)
return result
file1 = codecs.open(sys.argv[1],'r+','cp1251')
filelines = file1.readlines()
file1.close()
with codecs.open(sys.argv[1] + ".unique", "w", "cp1251") as output:
output.writelines(uniquelines(filelines))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment