Skip to content

Instantly share code, notes, and snippets.

@bmaeser
Created September 7, 2011 00:37
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bmaeser/1199425 to your computer and use it in GitHub Desktop.
Save bmaeser/1199425 to your computer and use it in GitHub Desktop.
good movies list with bash, awk and imdb
#!/bin/bash
MIN_RATING=7
MIN_VOTES=50000
usage="usage: imdb-ratings.sh -r MIN_RATING -v MIN_VOTES"
while getopts "r:v:h" options; do
case $options in
h ) echo $usage
exit 0
;;
r ) MIN_RATING=$OPTARG
;;
v ) MIN_VOTES=$OPTARG
;;
\? ) echo "you are doing it wrong :-("
echo $usage
exit 0
;;
esac
done
if [ ! -f ./ratings.list ]; then
# get the latest ratings-list from imdb
# more mirrors at http://www.imdb.com/interfaces#plain
wget ftp://ftp.fu-berlin.de/pub/misc/movies/database/ratings.list.gz
gunzip ratings.list.gz
fi
awk -v r=$MIN_RATING -v v=$MIN_VOTES '$3>=r && $2>=v && $2~/[0-9]+/ && $3~/[0-9]+/ && $NF!="(VG)" && $NF!="(V)" {print $0 } ' ratings.list
usage:
$ ./imdb.sh -r MINIMUM_RATING -v MINIMUM_VOTES
where both parameters are optional and default to:
-r 7
-v 50000
$ ./imdb.sh -r 9.2 -v 100000
will give you:
0000000125 785610 9.2 The Shawshank Redemption (1994)
0000000125 582037 9.2 The Godfather (1972)
0000000017 105243 9.6 "Band of Brothers" (2001)
0000000016 178326 9.4 "Game of Thrones" (2011)
0000000125 582037 9.2 The Godfather (1972)
0000000125 785610 9.2 The Shawshank Redemption (1994)
(Top 250 movies are listed twice)
only the 2011 movies? no problem, grep is your friend:
$ ./imdb.sh -r 9.2 -v 100000 | grep 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment