Re: Removing blank lines in a file...
- From: Hein RMS van den Heuvel <heinvandenheuvel@xxxxxxxxx>
- Date: Tue, 11 Dec 2007 18:37:38 -0800 (PST)
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.
.
- Follow-Ups:
- Re: Removing blank lines in a file...
- From: Carl Friedberg
- Re: Removing blank lines in a file...
- References:
- Removing blank lines in a file...
- From: apogeusistemas
- Re: Removing blank lines in a file...
- From: qawest
- Removing blank lines in a file...
- Prev by Date: Re: Removing blank lines in a file...
- Next by Date: Re: VMS like search utility for Windows
- Previous by thread: Re: Removing blank lines in a file...
- Next by thread: Re: Removing blank lines in a file...
- Index(es):
Relevant Pages
|