to directly remove the lines you could:
sed -rinri '/.{4}/!d' /path/to/file Or BRE:
sed -i '/.\{4\}/!d' /path/to/file If a line does not contain 4 or more characters it is deleted.
f=/path/to/file cat <<GREP >"$f" $(grep -E ".{4}" "$f") GREP Doing the above in command-substitution subshell will ensure that grep gets a read descriptor on it before cat starts writing to it, but the <<HEREDOC will also ensure that the result remains streamed and does not cause argument length errors.