* modify sed command to work in both gnu sed and mac os sed https://stackoverflow.com/a/4247319 * use printf everywhere for more compatibility * add some error checking