Thread: line stiching

Page 2 of 2 First 12
  • Jump to page:
    #16
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Location
    Prague, Czech Rep.
    Posts
    117
    Rep Power
    15
    Originally Posted by dsshed
    Hi

    i have data in files as shown below.

    this is line one.

    this is line two.


    this is line four.
    this is line five.

    i have got rid of the empty lines by running the command sed '/^$/d'
    and getting the file to the format below



    this is line one.
    this is line two.
    this is line three.
    this is line four.
    this is line five.

    i am asking your help/advise to end up with a file
    format as below.

    this is line one.this is line two.this is line three.this is line four.this is line five.

    basically from the original file that i have, i want to get rid
    of all the blank lines and then i want to get rid of all
    new line charaters and stich all lines into one BIG SINGLE line
    of data.

    thanks for your time

    What about a simple C program? You can write it as you wish and need not guess and try how the system commands work with huge files:

    #include<stdio.h>

    int main(int argc, char* argv[])
    {
    int c;

    while ((c = fgetc(stdin)) != EOF) {
    if (c != '\n')
    fputc(c, stdout);
    }
    }

    You can of course add test for succesfull read, return the completion code ...

    Regards
  2. #17
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Location
    Prague, Czech Rep.
    Posts
    117
    Rep Power
    15
    Originally Posted by dsshed
    Hi

    i have data in files as shown below.

    this is line one.

    this is line two.


    this is line four.
    this is line five.

    i have got rid of the empty lines by running the command sed '/^$/d'
    and getting the file to the format below

    this is line one.
    this is line two.
    this is line three.
    this is line four.
    this is line five.

    i am asking your help/advise to end up with a file
    format as below.

    this is line one.this is line two.this is line three.this is line four.this is line five.

    basically from the original file that i have, i want to get rid
    of all the blank lines and then i want to get rid of all
    new line charaters and stich all lines into one BIG SINGLE line
    of data.

    thanks for your time

    What about a simple C program? You can write it as you wish and do not need to guess how the system tools work with huge files:

    #include<stdio.h>


    int main(int argc, char* argv[])
    {
    int c;

    while ((c = fgetc(stdin)) != EOF) {
    if (c != '\n')
    fputc(c, stdout);
    }
    }

    You can of course add test for reading errors, return the return code and and and...

    Regards
Page 2 of 2 First 12
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo