formatting columns

Hi

I have a file that is several gigs in size and basically I want to change the format of it. Obviously I cannot go through it manually.

The file looks like this:

897	2
901	2
905	2
909	2
913	2
917	2
921	2
925	2
929	2
933	2
937	2
941	2
945	2
949	0
953	0
957	0
961	0
965	0
969	0
973	1
977	1
981	1
985	1
989	1
993	1
997	1
1001	1
1005	1
1009	1

I want the output so that it will look like this:

897  945  2
949  969  0
973  1009  1

basically compressing the file into something more simple. The initial file is tab separated and it would be great to have the output the same way.

Thanks

Kyle

This should do it based on your sample:

awk  '
    s"" != $2 {                  # s"" handles the case where $2 is 0 on the first record
            if( NR > 1 )
                printf( "%s\t%s\t%s\n", f, l, s );
            f = $1;
            s = $2;
            next;
    }

    { l = $1; }
    END { printf( "%s\t%s\t%s\n", f, $1, s ); }
' input-file >output-file
1 Like