Delete blank line in regular file

Hi all,

I have file1 with line blank e.g.

$cat file1
aaa  111 222 333 444
bbb 555 666 777 888
ccc
ddd 1010 1010 1010 
eee

then i need delete the lines blank (3 and 5) so show

$cat file1
aaa  111 222 333 444
bbb 555 666 777 888
ddd 1010 1010 1010 

Thanks you,

There are no blank lines in your file1 - I assume you mean you want to delete all rows which contain no columns except the first one?

What have you tried so far?

Yes sorry exactly delete all rows which contain blank

$cat file1 
aaa  111 222 333 444 
bbb  555 666 777 888 
ccc 
ddd  1010 1010 1010  
eee

to

$cat file1 
aaa  111 222 333 444 
bbb 555 666 777 888 
ddd 1010 1010 1010

your request is not clear

if you want to delete completely empty lines, try sed

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

your example will work with

awk 'NF!=1' file 
1 Like

Hello aav1307,

Following may help you in same.(Not tested though)
Code 1: Following one will check if number of fields are one or line is empty it will not print those lines.

awk '{if(NF==1 || $0 ~ /^$/){next} else {print $0}}' Input_file

Code 2:Following one will look only for lines which have more than 1 field.

awk 'NF>1' Input_file

Code 3: If you want to simply remove empty lines in file.

grep -v '^$' Input_file

Thanks,
R. Singh

1 Like

Yes fine this work

awk 'NF!=1' file