The problem with file is that it returns a non-uniform and non-parsable data. Its output is readable for a human but not for a computer.

EDIT: I see it has a -i option which outputs mime-type instead of human readable strings. That's more interesting.