Ah, silly me, I could've avoided calling sed at all by using NAMEDIR=$(echo ${f%.*} to remove the extension instead.