DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Convert Sqlite DB To TXT Cookies Format
#!/bin/bash
set -e
# Replace a column field for each line in stdin
replace_column_value() {
awk "BEGIN{OFS=FS=\"$1\"} {\$$2 = ((\$$2==\"$3\")?\"$4\":\"$5\"); print}"
}
# Convert a Mozilla sqlite cookie file to the old txt format
mozilla_cookies_sqlite2txt() {
echo "# Netscape HTTP Cookie File"
echo ".mode tabs
SELECT host, (host GLOB '.*'), path, 'FALSE', expiry, name, value
FROM moz_cookies;" | sqlite3 "$1" | \
replace_column_value "\t" 2 "1" "TRUE" "FALSE" | \
recode iso8859-1..utf-8 | tr -d '[áéÃóúà èìòù]'
}
FILE=$1
mozilla_cookies_sqlite2txt "$FILE"





