Last active
September 17, 2017 12:03
-
-
Save AnasAboreeda/29f54d713722bc28839d51bc9f676bef to your computer and use it in GitHub Desktop.
[Delete duplicated lines]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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