AWK or otherway to convert transpose Columns to Rows
From: Akhwashah (akhwashah._at_WARMmail.com)
Date: 06/29/05
- Next message: Chris F.A. Johnson: "Re: while read : slow"
- Previous message: luc: "Re: while read : slow"
- Next in thread: John L: "Re: AWK or otherway to convert transpose Columns to Rows"
- Reply: John L: "Re: AWK or otherway to convert transpose Columns to Rows"
- Reply: Bruce Barnett: "Re: AWK or otherway to convert transpose Columns to Rows"
- Reply: Ed Morton: "Re: AWK or otherway to convert transpose Columns to Rows"
- Reply: Greg Beeker: "Re: AWK or otherway to convert transpose Columns to Rows"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 29 Jun 2005 17:00:54 +1000
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
- Next message: Chris F.A. Johnson: "Re: while read : slow"
- Previous message: luc: "Re: while read : slow"
- Next in thread: John L: "Re: AWK or otherway to convert transpose Columns to Rows"
- Reply: John L: "Re: AWK or otherway to convert transpose Columns to Rows"
- Reply: Bruce Barnett: "Re: AWK or otherway to convert transpose Columns to Rows"
- Reply: Ed Morton: "Re: AWK or otherway to convert transpose Columns to Rows"
- Reply: Greg Beeker: "Re: AWK or otherway to convert transpose Columns to Rows"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|