Last active
June 11, 2025 21:13
-
-
Save mbejda/a2c0ecc02bb71de4e2bca718d3705ebb to your computer and use it in GitHub Desktop.
fbcid
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
LOG_FILE="access.log" | |
OUTPUT_FILE="fbcid_report.csv" | |
if [ ! -f "$LOG_FILE" ]; then | |
echo "Error: Log file not found at '$LOG_FILE'" | |
exit 1 | |
fi | |
count=0 | |
echo '"Date","FBCID","UserAgent"' > "$OUTPUT_FILE" | |
grep "fbcid=" "$LOG_FILE" | while IFS= read -r line; do | |
date=$(echo "$line" | awk -F'[][]' '{print $2}') | |
fbcid=$(echo "$line" | grep -oP 'fbcid=[^&" ]+' | cut -d'=' -f2) | |
user_agent=$(echo "$line" | awk -F'"' '{print $6}') | |
if [ -n "$fbcid" ]; then | |
echo "\"$date\",\"$fbcid\",\"$user_agent\"" >> "$OUTPUT_FILE" | |
((count++)) | |
fi | |
done | |
echo "--------------------------------------------------" | |
echo "Processing complete." | |
echo "Total records with an fbcid found: $count" | |
echo "Report saved to: $OUTPUT_FILE" | |
echo "--------------------------------------------------" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment