Hi All,
How do i remove continuos blank lines from a file.
I have a file with data:
abc;
def;
ghi;
jkl;
mno;
pqr;
In the above file, there are two blank lines. I want to remove, one out of them.
My output should look like:
abc;
def;
ghi;
jkl;
mno;
pqr;
With the below command, all the blank lines are getting deleted. I don't want that. I have to remove one out of two blanks.
sed -i '/^$/d' my_file
The above command is removing all the blank lines. But i want to keep only one blank line if more than one blank lines avail. I want to remove all other blank lines.
---------- Post updated at 06:22 PM ---------- Previous update was at 06:17 PM ----------
awk '/^$/{ if (! blank++) print; next } { blank=0; print }' my_file
or
awk 'NR==1 || NF || prvNF {print} {prvNF=NF}' my_file
Any of the above codes are working fine for me..
Thank you all!!!!!!!