Skip to content

Instantly share code, notes, and snippets.

@mbejda
Last active June 11, 2025 21:13
Show Gist options
  • Save mbejda/a2c0ecc02bb71de4e2bca718d3705ebb to your computer and use it in GitHub Desktop.
Save mbejda/a2c0ecc02bb71de4e2bca718d3705ebb to your computer and use it in GitHub Desktop.
fbcid
#!/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