Use fileinput instead of sed.