Re: Removing blank lines in a file...



Yeah.. really can't figure that out?
Anyway, just to be cute...

How about a truly minimalistic awk program:

$ gawk "length" file.dat

This executes the length function on the default input line $0 and
take the default action to print $0 if true ( != 0)
If you also want to get rid of lines with just spaces or tabs, change
to the even shorter:

$ gawk "NF" file.dat

That NF is a symbol representing the number of 'fields' on the default
input line, if true, take default action: print!
A more explicit way to write that:

$ gawk "/[^ \t]/" file.dat /out=stripped.dat

This uses a regular expresion to look for a string which contains
characters NOT (^) in the character set space and tab ([ \t])

In Perl that could be

$ perl -ne "print if /\S/" file.dat

in perl regexpr's the \s means 'whitespace', and \S means NOT
whitespace

The test for an empty line in perl seems to be handicapped with the
new-line or not.
This works for me:

$ perl -lne "print if length" file.dat > stripped.dat

grins,
Hein.
.



Relevant Pages

  • Re: Removing blank lines in a file...
    ... gawk 3.1.6 was released this summer. ... In Perl that could be ... in perl regexpr's the \s means 'whitespace', ...
    (comp.os.vms)
  • Re: Attempt #3, adding a new command sfilter
    ... have you seen how much crap gets installed when you add perl? ... Why not install the gawk port on the machines you need this on ... features) to our base-system awk. ...
    (freebsd-current)
  • Re: complex text file manipulation
    ... I'll look into gawk further ... but I feel this kind of job is one for a fully featured language (Perl ... 3.Take next line extracting company name and second net amount if any ... 4.Keep looking down the lines addding net amount to running total until ...
    (comp.unix.shell)
  • Re: complex text file manipulation
    ... >Thanks for all help so far - sorry about problems with people viewing ... I'll look into gawk further ... >but I feel this kind of job is one for a fully featured language (Perl ... The talk of linux boxes and multiple unix tools is a big ...
    (comp.unix.shell)
  • Re: Script help: convert music files to be compatible with MPD
    ... It looks like something that might be easier with gawk than Perl, ... Maybe its just an odd quirk of mine, but I find gawk easier to write than ... either the artist's name or the album name. ... martin@ | Martin Gregorie ...
    (uk.comp.os.linux)