Skip to content

Instantly share code, notes, and snippets.

@zeroDivisible
Created June 20, 2013 22:12
Show Gist options
  • Save zeroDivisible/5827190 to your computer and use it in GitHub Desktop.
Save zeroDivisible/5827190 to your computer and use it in GitHub Desktop.
General bash script.
#!/bin/bash
case $1 in
tags)
# extract tags
cat $2 | cut -d '|' -f 8 | sed "y/;/\n/;" | sed -e '/
/d' | sort | uniq > tags
;;
movies)
# extract movie details
cat $2 | cut -d '|' -f 1-6 | awk -F'|' '{split($5,duration,"m"); minutes=duration[1]; $5=minutes * 60 + duration[2];printf "insert into movies(source_id, external_id, title, url, embed_url, duration, date_added, deleted) values (2, %s, '\''%s'\'', '\''%s'\'', '\''%s'\'', %s, '\''%s'\'', false);\n",$1, $4, $2, $3, $5, $6}' > movies
;;
thumbs)
# extract movie thumbnails
cat $2 | tail -n +1 | cut -d '|' -f 1,7 | awk -F'|' '{split($2,thumbs,";"); for (i in thumbs) printf "insert into thumbs (movie_id, thumb_url, sorting_order) select record_id, '\''%s'\'', %s from movies where source_id = 2 and external_id = %s;\n", thumbs[i], i, $1 }' > thumbs
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment