Dec-29-2021, 10:07 AM
I have a bunch of text files that look this.
File1.txt
Any help, How to get this task done?
H0002 Version 3 H0003 Date_generated 5-Aug-81 H0004 Reporting_period_end_date 09-Jun-99 H0005 State WAA H0999 Tene_no/Combined_rept_no E79/38975 H1000 Sae_Id GAM_E GAM_N H1001 Tene_holder Magnetic Resources NLWant to seperate text data based on the first column value. First column start with H and followed by a number. If a number is less than 1000, I want to save as file1.txt and if a number is greater or equal to 1000 I want to save in a different txt file2.txt.
File1.txt
H0002 Version 3 H0003 Date_generated 5-Aug-81 H0004 Reporting_period_end_date 09-Jun-99 H0005 State WAA H0999 Tene_no/Combined_rept_no E79/38975File2.txt
H1000 Sae_Id GAM_E GAM_N H1001 Tene_holder Magnetic Resources NLMy python code:
import warnings from pathlib import Path import time import parser import argparse import pandas as pd pd.set_option('display.max_rows', None) warnings.filterwarnings('ignore') parser = argparse.ArgumentParser(description='Process some integers.') parser.add_argument('-path', help='define the directory to folder/file') parser.add_argument('-path_save', help='define where to save the file') parser.add_argument('--verbose', help='display processing information') start = time.time() def main(path_txt, path_save, verbose): if path_txt.is_file(): txt_files = [Path(path_txt)] # For One File else: txt_files = list(Path(path_txt).glob("*.txt")) for fn in txt_files: with open(fn) as f: text = f.read().strip() print(text) if __name__ == '__main__': start = time.time() args = parser.parse_args() path = Path(args.path) path_save = Path(args.path_save) verbose = args.verbose main(path, path_save, verbose) # Calling Main Function print('Processed time:', time.time() - start) # Total Time
Any help, How to get this task done?