Remove blank lines using cat command

plz help me to figure it out

how i remove empty or blank files using cat command.

i will be very thankful if u send me this answer...

thanks

You can remove empty or blank lines with the following command:

awk NF file > newfile

hmm... How can i fly to the moon using an invalidated credit card and a screwdriver?

The short answer is: you can't because the tool you want to use (in this case "cat") isn't designed to do what you want. (Actually "cat" is for conCATenating files.)

The long answer is: you might want to rephrase/rethink your question and get a better answer. But it won't even stop at that. Rethinking your question will put you into a state of mind where the solution will come more easily to you, not only because you will get better answers but because you may find it out yourself. Defining correctly (rigidly and meticulously) the goal is - more often than not - already three quarters of the solution.

There are several tools doing perfectly what you want, Unix is rich in all sorts of text filters: sed, awk, sort, and even the native shell can do what you want. You already got a solution in awk, so here is one in sed:

sed '/^$/d' /path/to/input > /path/to/output

I hope this helps.

bakunin

Actually, GNU cat has enough bloat that it can delete repeated blank lines ( cat -s ), so it is somewhat surprising that there is no option for the removal of all blank lines.. :slight_smile: