sed -n "s/foo/bar/; P" > tmpfilecat tmpfile