Removing blank lines from a file

Using sed

sed -i '/^[[:space:]]*$/d' my_file

Using awk

awk -i inplace NF my_file

NOTE: The -i flag in above two commands does “in place” editing of the files, so if you just want to try the command without editing the file skip -i

In my experience awk does the best job in deleting blank lines from a file.

Leave a Reply

Your email address will not be published.