Solved

Shell - syntax to remove blank lines

Posted on 2014-04-02
10
274 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 77

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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 77

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

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…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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…
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.:

786 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