-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdedupe_lines
More file actions
executable file
·40 lines (30 loc) · 918 Bytes
/
dedupe_lines
File metadata and controls
executable file
·40 lines (30 loc) · 918 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/python3
import sys
import argparse
def dedupe_and_sort(input_lines, sort=False):
# Remove duplicates using a set
unique_lines = set(input_lines)
# Convert to list for sorting or consistent output
result = list(unique_lines)
if sort:
result.sort()
return result
def main():
parser = argparse.ArgumentParser(
description="Deduplicate lines from stdin, with optional alphabetical sorting."
)
parser.add_argument(
"--sort",
action="store_true",
help="Sort the deduplicated lines alphabetically."
)
args = parser.parse_args()
# Read from stdin and strip whitespace
input_lines = sys.stdin.read().strip().splitlines()
# Process the lines
result = dedupe_and_sort(input_lines, sort=args.sort)
# Print the output
for line in result:
print(line)
if __name__ == "__main__":
main()