Solved

How can I remove blank lines from the file ?

Posted on 2000-03-23
8
224 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: 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 50 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Move nodes from one TSM to another. 3 96
SQUD PROXY SERVER, UNIX, SLL/HTTPS 5 117
Unix Script: Loop over all days of a month 17 117
remove one line from a file in solaris 8 59
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
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…

730 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