Solved

How can I remove blank lines from the file ?

Posted on 2000-03-23
8
223 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 20

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 20

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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Accepted Solution

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

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

832 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