-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse.py
28 lines (28 loc) · 1.5 KB
/
parse.py
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
import subprocess # Importing the subprocess module to run external shell commands
import sys # Importing the sys module to access command-line arguments and system functions
# Ensure exactly one argument is passed to the script (the input file)
if len(sys.argv) != 2:
# Display correct usage information
print("Usage: python parse.py <input_file>")
sys.exit(1) # Exit the script with an error code
try:
# Get the file name from the command-line argument
file_name = sys.argv[1]
# Execute a shell script ("parse.sh") with the file name as an argument
# Check if the script runs successfully
if subprocess.check_output(["bash", "parse.sh", file_name]):
# If the script runs successfully, generate a new file name with "_awk" appended
new_file_name = file_name+"_awk"
# Open the new file and read its content
with open(new_file_name, 'r') as file:
filedata = file.read()
# Remove a specific keyword ('PRION:') from the file content
filedata = filedata.replace('PRION:', '')
# Write the modified content back to the same file
with open(new_file_name, 'w') as file:
file.write(filedata) # Save the updated content
# Indicate that the operation was successful
print("The file was successfully parsed")
except Exception as e:
# If an error occurs during the try block, catch the exception and display the error message
print(e) # Print the exception message to understand what went wrong