bash script for iterative map reduce