Do you want to replace them with something, or delete them entirely? Either way, it can be done with sed
. To delete:
sed -i -e '/^,\+$/ D' yourfile1.csv yourfile2.csv ...
To replace: well, see wnoise's answer, or if you don't want to create new files with the output,
sed -i -e '/^,\+$/ s//replacement/' yourfile1.csv yourfile2.csv ...
or
sed -i -e '/^,\+$/ c\
replacement' yourfile1.csv yourfile2.csv ...
(that should be entered exactly as is, including the line break). Of course, you can also do this with awk
or perl
or, if you're only deleting lines, even grep
:
egrep -v '^,+$' < oldfile.csv > newfile.csv
I tested these to make sure they work, but I'd advise you to do the same before using them (just in case). You can omit the -i
option from sed
, in which case it'll print out the results (rather than writing them back to the file), or omit the output redirection >newfile.csv
from grep
.
EDIT: It was pointed out in a comment that some features of these sed
commands only work on GNU sed
. As far as I can tell, these are the -i
option (which can be replaced with shell redirection, sed ... <infile >outfile
) and the \+
modifier (which can be replaced with \{1,\}
).