Re: AWK or otherway to convert transpose Columns to Rows
From: Greg Beeker (gbeeker_at_gmail.com)
Date: 06/29/05
- Next message: Robert Maas, see http://tinyurl.com/uh3t: "Re: tell the difference between url and ip address"
- Previous message: alex221_at_pisem.net: "Re: Variable value in while loop"
- In reply to: Akhwashah: "AWK or otherway to convert transpose Columns to Rows"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 29 Jun 2005 10:41:09 -0700
Akhwashah wrote:
> HI All,
>
>
> I have a data file with roughly the following format :
>
> AAA,BBB,CCC,DDD,1234,5678,555,678....999
>
> basically a list of text fields, with several columns of data by month
>
> Which I would like converted to :
>
> AAA,BBB,CCC,DDD,JAN,1234
> AAA,BBB,CCC,DDD,FEB,5678
> AAA,BBB,CCC,DDD,MAR,555
> AAA,BBB,CCC,DDD,MAR,678
> :
> AAA,BBB,CCC,DDD,DEC,999
>
> I have been able to get it happening very manually by using multiple print
> statments in an awk program file, but I would like to make it more dynamic,
> as the columns may represent different months at any point in time, so i was
> hoping to somehow provide an argument. ie data could be for JAN-DEC or
> AUG-DEC..
>
> The first 8 fields are dimensions , the remain rows are data columns that
> need to be transposed as I described above.
>
> An example of what I have put into my awkprog file is (I have to change the
> order of some of the fields too):
> { print $5 "\t" $8 "\t" $3 "\t" $6 "\t" $4 "\t" "AUG04" "\t" $1 "\t" $7 "\t"
> $9 }
> { print $5 "\t" $8 "\t" $3 "\t" $6 "\t" $4 "\t" "SEP04" "\t" $1 "\t" $7 "\t"
> $10 }
> { print $5 "\t" $8 "\t" $3 "\t" $6 "\t" $4 "\t" "OCT04" "\t" $1 "\t" $7 "\t"
> $11 }
> { print $5 "\t" $8 "\t" $3 "\t" $6 "\t" $4 "\t" "NOV04" "\t" $1 "\t" $7 "\t"
> $12 }
> { print $5 "\t" $8 "\t" $3 "\t" $6 "\t" $4 "\t" "DEC04" "\t" $1 "\t" $7 "\t"
> $13 }
>
> I would need one print line per column, the number of data columns may not
> always be the same
>
> Can someone give me any ideas on how to go about this?
>
> Thanks,
> Imran
This might not be exactly what you are looking for, but I remember
reading about a rot.shar C script somewhere that will rotate a file so
that rows become columns.
This search http://www.google.com/search?biw=1003&hl=en&q=rot.shar
returns this example examples.oreilly.com/upt3/split/rot.shar
- Next message: Robert Maas, see http://tinyurl.com/uh3t: "Re: tell the difference between url and ip address"
- Previous message: alex221_at_pisem.net: "Re: Variable value in while loop"
- In reply to: Akhwashah: "AWK or otherway to convert transpose Columns to Rows"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|