push compareHostname
This commit is contained in:
parent
07641f871d
commit
d985756c9a
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,3 +1,8 @@
|
||||
# Nick self-add
|
||||
|
||||
# sensitive files that could not be shared
|
||||
rawFiles/
|
||||
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
|
@ -1,2 +1,7 @@
|
||||
# SW_PythonScripts
|
||||
|
||||
Random Scripts for Making Life Easier
|
||||
|
||||
## compareHostname.py
|
||||
|
||||
Allows to compare between 2 text files, 'hostname="{...}"', and print out unique hostnames for easier management
|
36
compareHostname.py
Normal file
36
compareHostname.py
Normal file
@ -0,0 +1,36 @@
|
||||
import re
|
||||
|
||||
def extract_hostnames(file_path):
|
||||
hostname_pattern = r'hostname="([^"]+)"'
|
||||
hostnames = set() # Use a set to avoid duplicates within the same file
|
||||
|
||||
try:
|
||||
with open(file_path, 'r', encoding='utf-8') as file:
|
||||
for line in file:
|
||||
matches = re.findall(hostname_pattern, line)
|
||||
hostnames.update(matches)
|
||||
except FileNotFoundError:
|
||||
print(f"File not found: {file_path}")
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {e}")
|
||||
|
||||
return hostnames
|
||||
|
||||
if __name__ == "__main__":
|
||||
file1 = "rawFiles/file1.txt"
|
||||
file2 = "rawFiles/file2.txt"
|
||||
|
||||
hostnames_file1 = extract_hostnames(file1)
|
||||
hostnames_file2 = extract_hostnames(file2)
|
||||
|
||||
# Find unduplicated hostnames
|
||||
unique_to_file1 = hostnames_file1 - hostnames_file2
|
||||
unique_to_file2 = hostnames_file2 - hostnames_file1
|
||||
|
||||
print("Hostnames unique to file1:")
|
||||
for hostname in unique_to_file1:
|
||||
print(hostname)
|
||||
|
||||
print("\nHostnames unique to file2:")
|
||||
for hostname in unique_to_file2:
|
||||
print(hostname)
|
Loading…
x
Reference in New Issue
Block a user