Solved

How can I remove blank lines from the file ?

Posted on 2000-03-23
8
222 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sort command HPUX 11 76
NTP Server in VMware 5 224
Using gawk to read and manipulate multiple texts from a file 1 60
Field name with special character (Ñ) in Oracle 11 51
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
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 find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

777 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