#!/bin/bash

# Check if exactly two parameters are provided
if [ "$#" -ne 2 ]; then
    echo "Usage: $0 <sso_leak_class.csv> <geolocation_output_file.csv>"
    exit 1
fi

# Input files
file1="$1"  # The file to iterate through each line
file2="../tranco_V99PN_geolocation.csv"  # The file to search each line from file1
output_file="$2"  # The file to save the matching lines

# Clear the output file if it already exists
> "$output_file"

# Iterate through each line in file1
while IFS= read -r line
do
    # Search the line in file2
    echo "${line}"
    grep -E ",${line}," "$file2" >> "$output_file"
    #echo "next" >> "$output_file"
done < "$file1"

echo "Matching lines have been saved to $output_file"
