gpt-4-0314· OpenAI
WildChat-4.8M (AI2)
I need to write a python script to extract information from a file, e.g., cat_0.log:…
- User
I need to write a python script to extract information from a file, e.g., cat_0.log:
981209381,-2.2827243139,-0.6257637378\\Version=ES64L-G16RevC.01\State= 3-A\HF=-1544.3162072\S2=2.005397\S2-1=0.\S2A=2.000016\RMSD=4.750e-09\R MSF=3.909e-06\Dipole=0.9951136,-0.7979979,0.2975911\Quadrupole=20.6598 676,-8.7620326,-11.8978351,-3.1542869,-3.5442806,2.4678866\PG=C01 [X(C 25H26Ir1N1O1P1)]\\@ NO HUMAN INVESTIGATION CAN BECOME REAL SCIENCE WITHOUT GOING THROUGH MATHEMATICAL PEOPLE. -- LEONARDO DA VINCI, IN "PENSIERI" CA. 1492 Job cpu time: 1 days 4 hours 15 minutes 7.7 seconds. Elapsed time: 0 days 1 hours 47 minutes 14.2 seconds. File lengths (MBytes): RWF= 304 Int= 0 D2E= 0 Chk= 32 Scr= 1 Normal termination of Gaussian 16 at Sun Apr 16 00:37:47 2023.If the last line ends as "Normal termination ...", I will need to move the file to a new folder. Can you write a draft python script?
- Assistant
Sure, here's a draft Python script to accomplish this task:
import os import shutil def main(): # Define the file path and the destination folder path file_path = 'cat_0.log' dest_folder_path = 'path/to/new/folder' with open(file_path, 'r') as file: lines = file.readlines() last_line = lines[-1].strip() # Check if the last line indicates normal termination if last_line.startswith("Normal termination"): # Create the destination folder if it doesn't exist os.makedirs(dest_folder_path, exist_ok=True) # Move the file to the destination folder shutil.move(file_path, os.path.join(dest_folder_path, os.path.basename(file_path))) print(f"File '{file_path}' moved to '{dest_folder_path}'") else: print(f"File '{file_path}' does not have normal termination.") if __name__ == "__main__": main()Before running the script, change the
'path/to/new/folder'string to the desired destination folder.