[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Shell - syntax to remove blank lines

Posted on 2014-04-02
10
Medium Priority
?
281 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
[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
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 80

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
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.

 
LVL 80

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
 
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 2000 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

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…
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
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.:
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

656 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