Stripping blank lines from top and bottom of file.

Stripping blank lines from top and bottom of file.

Post by Roy Smit » Mon, 08 Jan 2001 05:32:43



What's the simpliest way to strip the blank lines from the top and bottom of
a file in a shell script, but not touch blank lines in the middle?  It
*seems* like the kind of thing which should be a one-liner in sed.
 
 
 

Stripping blank lines from top and bottom of file.

Post by Tim Heane » Mon, 08 Jan 2001 11:19:49



> What's the simpliest way to strip the blank lines from the top and bottom of
> a file in a shell script, but not touch blank lines in the middle?  It
> *seems* like the kind of thing which should be a one-liner in sed.

Here's one way to do it with Perl

  perl -0 -e '$_=<>;s/^\n+//;s/\n+$/\n/;print;' < infile > outfile

Tim

 
 
 

1. Strip blank lines from a .txt file

I have a text file that can contain a large amount of data.
However after using the sort command, I am left with numerous blank
lines. Does anyone know how these could be stripped?

The file is in the format

eggs
baccon

saugage
tomatos
blackpudding

mushrooms
..etc

Thanks
Mick

2. add tape

3. vi: convert double blank lines to single blank lines???

4. Apache's mod_action problem

5. multiple blank lines -> one blank line

6. RAM doubler for LINUX

7. stripping trailing blank lines

8. XFree86 2.1 and Mach32 (Uploaded)

9. vi: convert double blank lines to single blank lines???

10. skipping empty lines at the top/bottom

11. HELP: How do I read a file line-by-line without getting spaces stripped?

12. stripping top line

13. Put file lines in an array: how keep line blanks in the string?