remove empty lines using ed

remove empty lines using ed

Post by sirano dhepagano » Thu, 18 Dec 1997 04:00:00



Hi:

How can I remove empty lines from a file using ed or edit?

For example, I'd like to convert file A to B using and editor:

        File A:
        evaluate ($min=2.2)  
        evaluate ($max=4.0)  

        evaluate ($peak=1.5)  

        evaluate ($npeaks=400)        

        File B:
        evaluate ($min=2.2)  
        evaluate ($max=4.0)  
        evaluate ($peak=1.5)  
        evaluate ($npeaks=400)        

Note: 's/^$//g' does not work.

----------------------
Sirano Dhe-Paganon
Joslin Diabetes Center
Harvard Medical School
One Joslin Place
Boston, MA 02215
Tel 617-735-1934

 
 
 

remove empty lines using ed

Post by Declan Ford » Fri, 19 Dec 1997 04:00:00



> Hi:

> How can I remove empty lines from a file using ed or edit?
[snip]
> Note: 's/^$//g' does not work.

I tend to use only sed for such job, in sed
sed '/^$/d' file.txt
does the trick

In ed or edit the following works
:g/^$/d

Declan

--
 _________________________   ___________________________________
/ Declan Forde  (7-205)  ////                              }~{ /
\ Bosch Telecom GmbH     \\\\  Tel  : 07191-13-4366            \


\________________________\\\\__________________________________\

 
 
 

remove empty lines using ed

Post by Charles Dem » Fri, 19 Dec 1997 04:00:00




Quote:>Hi:

>How can I remove empty lines from a file using ed or edit?

>For example, I'd like to convert file A to B using and editor:

>    File A:
>    evaluate ($min=2.2)  
>    evaluate ($max=4.0)  

>    evaluate ($peak=1.5)  

>    evaluate ($npeaks=400)        

>    File B:
>    evaluate ($min=2.2)  
>    evaluate ($max=4.0)  
>    evaluate ($peak=1.5)  
>    evaluate ($npeaks=400)        

>Note: 's/^$//g' does not work.

awk can do this, sort of,
this will eliminate blank lines or those with only white space

awk 'NF>0' infile > outfile

in vi, you can join one line to another with the J command
if you do that on a blank line, or on the line above it,
that would eliminate the blank line

I don't use ed or edit, but check the man page.

Chuck Demas
Needham, Mass.

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.

 
 
 

1. Replacing >=1 white-space or empty lines with 1 empty line

Hello,

Could some kind soul please post a sed or awk script (or some other
universal UNIX tool) which scans its stdin for any adjacent set of
lines (\n terminated, 1 or more lines in the set) each of which is
either empty or all white-space (\t or ' '), and replaces each such
set in stdout with a single empty line (leaving all other throughput
unaltered).

So when (e.g.) you catted the file:

one
<empty>
two
<space>
<tab><space>
<empty>
three
<tab>
four

into it, the output is:

one
<empty>
two
<empty>
three
<empty>
four

Thanks if you can help!

2. fatal server error

3. How do I insert line numbers before each line using ed?

4. Corel Office for Java under Linux

5. Linux FAQ

6. Remove empty lines

7. FastCgiServer

8. Removing empty lines containing only CR/LF with sed?

9. removing empty lines

10. removing empty lines from multiple files...

11. Removing empty lines in emacs

12. Using ed to remove Carriage Returns from a file