Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing blank lines

I have a csv file in which every other line is blank. I have tried everything, nothing removes the lines. What should make it easier is that the the digits 44 appear in each valid line. Things I have tried:

grep -ir 44 file.csv
sed '/^$/d' <file.csv
cat -A file.csv
sed 's/^ *//; s/ *$//; /^$/d' <file.csv
egrep -v "^$" file.csv
awk 'NF' file.csv
grep '\S' file.csv
sed 's/^ *//; s/ *$//; /^$/d; /^\s*$/d' <file.csv
cat file.csv | tr -s \n

Decided I was imagining the blank lines, but import into Google Sheets and there they are still! Starting to question my sanity! Can anyone help?

like image 304
user4893295 Avatar asked Mar 18 '26 00:03

user4893295


1 Answers

sed -n -i '/44/p' file

-n means skip printing
-i inplace (overwrite same file)
- /44/p print lines where '44' exists

without '44' present

sed -i '/^\s*$/d' file

\s is matching whitespace, ^startofline, $endofline, d delete line

like image 58
josifoski Avatar answered Mar 20 '26 03:03

josifoski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!