Skip to content

Instantly share code, notes, and snippets.

@johan johan/fb-friends-to-csv.sh
Last active Aug 20, 2017

Embed
What would you like to do?
#! /bin/sh
# path to your unzipped Facebook html/friends.htm file
friends="$1"
year=$(
egrep -o '<div class="footer">Downloaded by .* on \w+, \d+ \w+ (\d+)' "$friends" \
| awk '{print $NF}'
)
echo 'date,name'
perl -pe 's:^.*?</ul>(.*?)</ul>.*:\1:' < "$friends" \
| tr '<' '\n' \
| sed -n '/^li>/s/^...//p' \
| sed -E 's/([a-z])\)$/\1 '${year}')/' \
| sed -E 's/^(.*) \(([0-9]+) (...)[a-z]* ([0-9]+)\)/\4-\3-\2,\1/' \
| sed -E 's/^([0-9]+)-(...)-([0-9]),/\1-\2-0\3,/' \
| sed -e 's/&#064;/@/g' -e "s/&#039;/'/g"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.