To remove blank lines with sed
:
sed -i '/^$/d' yourfile.csv
To remove lines consisting of a single $
:
sed -i '/^$$/d' yourfile.csv
Most versions of sed support the -i
switch; if yours does not you will need e.g. sed '/^$$/d' yourfile.csv > newfile.csv
.
Removing blank lines with white space is more complicated. This usually works:
sed '/^ *$/d' yourfile.csv
If this is not sufficient, try checking also for tabs. For older sed's, this will work:
sed '/^[ X]*$/d' yourfile.csv
where X
here a tab, entered via Control-V Tab.
Newer sed's will take a [ \t\r]*
or \s*
or [[:space:]]*
, sometimes requiring a -E
switch.