?
Solved

How can I remove blank lines from the file ?

Posted on 2000-03-23
8
Medium Priority
?
228 Views
Last Modified: 2010-04-21
Hi experts,

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

I am using SunOS.

Thanks in Advance!
0
Comment
Question by:sganta
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 21

Expert Comment

by:tfewster
ID: 2648684
grep -v ^$ your_file > new_file
0
 
LVL 4

Expert Comment

by:urim
ID: 2648685
awk 'NF > 0 {print $0}'

this will return the rows that have something in it.
0
 
LVL 21

Expert Comment

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

Nice one, urim
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Accepted Solution

by:
thacsi earned 200 total points
ID: 2648785
egrep -v "^ *$" will remove all blank lines including those with spaces.
0
 
LVL 21

Expert Comment

by:tfewster
ID: 2648821
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
 
LVL 4

Author Comment

by:sganta
ID: 2652026
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
 
LVL 4

Author Comment

by:sganta
ID: 2652029
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
 

Expert Comment

by:thacsi
ID: 2661028
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses
Course of the Month15 days, left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question