Re: Getting a text file rid of all superfluous blank lines

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Paul Smith wrote:
On 12/1/05, Les Mikesell <lesmikesell@xxxxxxxxx> wrote:

sed -e 's;^\w*$;;' file-to-clean | grep -v '^$'

Why not use egrep to do it in one pass? Something like:

egrep -v '^\w*$' file-to-clean

Neither of these leave any blank lines.  The idea was
to collapse repeated blank lines or lines containing only
white space to one.


So many ways of solving my problem show that this list is quite creative!

Paul


Do you have gcc installed on your system?

Mike
--
p="p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
This message made from 100% recycled bits.
You have found the bank of Larn.
I can explain it for you, but I can't understand it for you.
I speak only for myself, and I am unanimous in that!
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>

#define LINE_SIZE   1024

typedef enum { ST_ACCEPTING, ST_DISCARDING } State_t;

char    Line[LINE_SIZE];

int     IsBlankLine(const char *Line) {
    while (*Line && isspace(*Line))
        Line++;
    return *Line == '\0';
}

int     main(void) {
    State_t State;

    State = ST_ACCEPTING;
    while (fgets(Line,sizeof Line,stdin)) {
        switch (State) {
            case ST_ACCEPTING:
                fputs(Line,stdout);
                if (IsBlankLine(Line))
                    State = ST_DISCARDING;
                break;
            case ST_DISCARDING:
                if (!IsBlankLine(Line)) {
                    fputs(Line,stdout);
                    State = ST_ACCEPTING;
                }
                break;
            default:
                fputs("can't happen\n",stderr);
                return EXIT_FAILURE;
                break;
        }
    }
    return EXIT_SUCCESS;
}


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux