Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 282
  • Last Modified:

Shell - syntax to remove blank lines

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
joaotelles
Asked:
joaotelles
1 Solution
 
farzanjCommented:
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
 
arnoldCommented:
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
 
joaotellesAuthor Commented:
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.

 
arnoldCommented:
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
 
manny17Commented:
sed -n '/^$/d' file_name > file_name1
mv file_name1 file_name
0
 
MazdajaiCommented:
perl -i -ne 'print if /\S/' minus_first.lst

Open in new window

0
 
ozoCommented:
grep . file_name > file_name1
or
grep '[[:graph:]]' file_name > file_name1
0
 
joaotellesAuthor Commented:
Hi,

None of the solutions worked :(((

I have attached a sample fo the file.. maybe it helps.. Im running Solaris 10.
sample
sample
0
 
Dave GouldCommented:
They are not blank lines. Just very long lines. You need to remove the trailing spaces.

try
 sed 's/\W*$//' your_file
0
 
joaotellesAuthor Commented:
tks.
0

Featured Post

Industry Leaders: 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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now