SUMMARY: How can I add "new lines" in a large file ?

From: Sweatt, Wayne <sweatt_at_dps.state.nm.us>
Date: Mon, 27 Mar 2000 11:02:44 -0700

Thanks for the quick, plentiful responses.
I ended up using a short C program, provided by Frank Wortner.
Since my C coding ability doesn't really extend beyond "Hello World",
I used his code and it worked fine.

Here is the code:

---------------------------------------------------------------
#include <stdio.h>
#define FIXEDLENGTH 90 /* Change to an appropriate value */
main(argc, argv)
int argc;
char *argv[];
{
    char buff[FIXEDLENGTH];
    int n;

    while((n = fread(buff, sizeof(char), FIXEDLENGTH, stdin)) != EOF) {
        if (fwrite(buff, sizeof(char), FIXEDLENGTH, stdout) != n) {
            perror("fwrite"); exit(1);
        }
        if (fputc('\n', stdout) < 0) {
            perror("fputc"); exit(1);
        }
    }
    exit(0);
}
--------------------------------------------------------

Thanks also to:
Nancy Davis, Dr. Tom Blinn, Daniel Monjar,
Alessandro Brunengo, Alan Anguelo,
Paul Sand, Oisin McGuinness, Larye Parkins,
Claudio Tantignone

I actually tried 'tr', but it doesn't have the ability to
replace <string> with <string>\n.
It can substitute single chars or a repeating
string to a single char.
If I'm wrong here, someone tell me how.
vi didn't work either, it must use the line based sed code.
I would have used Perl myself, but having the
C code given to me was too easy.

***********************
Wayne Sweatt
Principal Software Analyst
Litton / PRC
505.827.9288
***********************

        -----Original Message-----
        From: Sweatt, Wayne [SMTP:sweatt_at_dps.state.nm.us]
        Sent: Monday, March 27, 2000 8:47 AM
        To: DU Mail List
        Subject: How can I add "new lines" in a large file ?

        I have just received a 19MB file containing ascii text.
        It contains no CR/LF - new lines.
        "wc -l" returns a '"0".
        It has a repeating pattern marking the beginning of each new line.
        I tried to sed substitute this pattern with a prepended '\n', but it
        just ran forever. I had to kill it.
        It appears that sed can't handle a file that large.

        What method can I use to insert these new lines ?
        Each line is also a fixed length.
        I think the fact that it is 19MB causes a problem.

        Thanks,
        ***********************
        Wayne Sweatt
        Principal Software Analyst
        Litton / PRC
        505.827.9288
        ***********************
Received on Mon Mar 27 2000 - 18:03:53 NZST

This archive was generated by hypermail 2.4.0 : Wed Nov 08 2023 - 11:53:40 NZDT