macOS
To achieve the same on a macOS machine:
awk -F',' 'NR>1{print $1","$2}' *.csv | sort | uniq -c | awk '{print $1","$2","$3}' > merged.csv
And the Python code to do the same (ChatGPT):
import csv
import os
from collections import Counter
# Iterate over all the CSV files in the current directory and extract the objects
objects = []
for filename in os.listdir():
if filename.endswith('.csv'):
with open(filename, 'r') as file:
reader = csv.reader(file)
objects += list(map(lambda row: (row[0], row[1]), list(reader)[1:]))
# Use Counter to count the occurrences of each object
object_counts = Counter(objects)
# Write the merged CSV file
with open('merged.csv', 'w', newline='') as file:
writer = csv.writer(file)
# Write the header row
writer.writerow(['count', 'Name', 'IP'])
# Iterate over the Counter items and write each object as a row in the CSV
for object, count in object_counts.items():
writer.writerow([count, *object])
Linux
netstat -tulpn
chkconfig <servicename> off # disable
sudo lsof -i -n -P