analyse a HPROF memory dump file from command line programmatically
ParseHeapDump.sh does what you're looking for. As for the follow up question I'm not sure what format the index files are stored in.
See bitbucket.org/joebowbeer/andromat, which is adapted from bitbucket.org/ekabanov/mat, which is a stripped-down command line version of Eclipse Memory Analyzer.