How can I remove blank lines from the file ?

Hi experts,

I have so many blank lines in the file.How can I remove those lines ?

I am using SunOS.

Thanks in Advance!
LVL 4
sgantaAsked:
Who is Participating?
 
thacsiCommented:
egrep -v "^ *$" will remove all blank lines including those with spaces.
0
 
tfewsterCommented:
grep -v ^$ your_file > new_file
0
 
urimCommented:
awk 'NF > 0 {print $0}'

this will return the rows that have something in it.
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
tfewsterCommented:
urim's answer is better, as mine would print a line that had spaces etc. on it

Nice one, urim
0
 
tfewsterCommented:
thacsi, if that's what is wanted, then urim was the first to give a correct solution. Please change your answer to a comment,  and allow sganta to decide which is the most useful.
0
 
sgantaAuthor Commented:
Hi Experts,

Thank you for all your help. Urim was the first to answer the question. So, I am giving points to him. Inany way
I will also give points to "thacsi" and "tfewster" for your help.

Lots of thanks
sganta
0
 
sgantaAuthor Commented:
I am sorry, by mistake I gave to thacsi, In any way I want to give points
to all of you. So I will give the points to urim and tfewster.
0
 
thacsiCommented:
Sqanta:

egrep -v "^$|^ *$|^\^I$" file
will remove null blank lines in parse 1, 1 to n spaces in parse 2 and tabs in parse 3. I tried it, it will work.

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.