Solved

Shell - syntax to remove blank lines

Posted on 2014-04-02
10
268 Views
Last Modified: 2014-04-07
Hi,

Im running Solaris 10 and I have the this file:

089724051000029770 551891074630

089724051000029776 551891074636

089724051000029857 551891074717

.
.

I want it not to have these blank lines anymore, it will look like something like this:

089724051000029770 551891074630
089724051000029776 551891074636
089724051000029857 551891074717
.
.

What would be the fastest way to do it?

Tks,
Joao
0
Comment
Question by:joaotelles
10 Comments
 
LVL 31

Expert Comment

by:farzanj
ID: 39972745
Try
sed /^$/d filename

Open in new window



For modifying the file (inline modification) you can do
sed -i '/^$/d' filename

Open in new window

0
 
LVL 76

Expert Comment

by:arnold
ID: 39972878
adding to farzanj to address spaces on line
sed -i '/^[ ]*$/d' filename
or to remove any empty line with white space
sed -i '/^\W+$/d' filename
0
 

Author Comment

by:joaotelles
ID: 39972932
Im running the option without the i because it failed..

> sed -i '/^$/d' minus_first.lst
sed: illegal option -- i
> sed -i '/^[ ]*$/d' minus_first.lst
sed: illegal option -- i

This is what Im running:
> sed /^$/d minus_first.lst > minus_1.txt
0
 
LVL 76

Expert Comment

by:arnold
ID: 39973260
You're on Solaris, the -i option I think is a GNU sed.
If your example does not work, try

awk ' (length ($0) >1 { print } ' filename

No check for empty spaces exclusion.
0
 

Expert Comment

by:manny17
ID: 39973542
sed -n '/^$/d' file_name > file_name1
mv file_name1 file_name
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 21

Expert Comment

by:Mazdajai
ID: 39973747
perl -i -ne 'print if /\S/' minus_first.lst

Open in new window

0
 
LVL 84

Expert Comment

by:ozo
ID: 39973759
grep . file_name > file_name1
or
grep '[[:graph:]]' file_name > file_name1
0
 

Author Comment

by:joaotelles
ID: 39974770
Hi,

None of the solutions worked :(((

I have attached a sample fo the file.. maybe it helps.. Im running Solaris 10.
sample
sample
0
 
LVL 5

Accepted Solution

by:
Dave Gould earned 500 total points
ID: 39974889
They are not blank lines. Just very long lines. You need to remove the trailing spaces.

try
 sed 's/\W*$//' your_file
0
 

Author Closing Comment

by:joaotelles
ID: 39984483
tks.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

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…
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 how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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.

747 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now