replaced sed with awk due to differences between GNU sed and OS X sed