-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabc
executable file
·37 lines (26 loc) · 993 Bytes
/
abc
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
#!/usr/bin/env python3
import sys
def merge_files(file_paths):
if not file_paths:
print("At least one file path is required.")
return
# Read all lines from all files, including the first one
all_lines = set()
for file_path in file_paths:
with open(file_path, 'r') as f:
all_lines.update(f.read().splitlines())
# Sort the unique lines
# sorted_lines = sorted(all_lines)
sorted_lines = sorted(all_lines, key=str.lower)
# Write the sorted, unique lines to the first file, overwriting its contents
with open(file_paths[0], 'w') as f:
for line in sorted_lines:
f.write(line + '\n')
print(f"Merged {len(file_paths)} files into {file_paths[0]}")
if __name__ == "__main__":
# Get file paths from command line arguments
file_paths = sys.argv[1:]
if not file_paths:
print("Usage: txt-line-merge-abc file1.txt file2.txt file3.txt ...")
else:
merge_files(file_paths)