Tuesday, July 26, 2022

[SOLVED] To remove blank lines in data set

Issue

I need a one liner using sed, awk or perl to remove blank lines from my data file. The data in my file looks like this -

Aamir
Ravi 

Arun


Rampaul
Pankaj

Amit

Bianca

These blanks are at random and appear anywhere in my data file. Can someone suggest a one-liner to remove these blank lines from my dataset.


Solution

it can be done in many ways.

e.g with awk:

awk '$0' yourFile

or sed:

sed '/^$/d' yourFile

or grep:

grep -v '^$' yourFile


Answered By - Kent
Answer Checked By - Marilyn (WPSolving Volunteer)