From e2d3b8788797711121c2033adec5a8219651427e Mon Sep 17 00:00:00 2001 From: sanj <67624670+iodrift@users.noreply.github.com> Date: Tue, 23 Jul 2024 12:07:58 -0700 Subject: [PATCH] Auto-update: Tue Jul 23 12:07:58 PDT 2024 --- txt-line-merge-abc | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100755 txt-line-merge-abc diff --git a/txt-line-merge-abc b/txt-line-merge-abc new file mode 100755 index 0000000..bebdab2 --- /dev/null +++ b/txt-line-merge-abc @@ -0,0 +1,36 @@ +#!/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) +