Advertisement
genericPaster

consolidate

May 8th, 2024
555
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.89 KB | None | 0 0
  1. import os
  2.  
  3. # goes through all text files in a directory
  4. # looks for lines starting with the target strings and put them all into one text file
  5.  
  6. target_strings = ["Model:", "MaxCtx:", "ProcessingTime:", "ProcessingSpeed:", "GenerationTime:", "GenerationSpeed:", "TotalTime:"]
  7.  
  8. matching_lines = []
  9.  
  10. for filename in os.listdir("."):
  11.     if filename.endswith(".txt"):
  12.         # Open the file and read its contents
  13.         with open(filename, "r") as f:
  14.             lines = f.readlines()
  15.  
  16.         for line in lines:
  17.             for target_string in target_strings:
  18.                 if line.lstrip().startswith(target_string):
  19.                     # If it matches, add it to our list of matching lines
  20.                     matching_lines.append(line.strip())
  21.  
  22. with open("consolidated.txt", "w") as f:
  23.     f.write("\n".join(matching_lines))
  24.  
  25. print("Consolidated file written to consolidated.txt")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement