Re: AWK or otherway to convert transpose Columns to Rows
From: Ed Morton (morton_at_lsupcaemnt.com)
Date: 06/29/05
- Next message: alex221_at_pisem.net: "Variable value in while loop"
- Previous message: Chris F.A. Johnson: "Re: Can ksh93 do 0..9 type of syntax for loop control?"
- In reply to: Akhwashah: "AWK or otherway to convert transpose Columns to Rows"
- Next in thread: Greg Beeker: "Re: AWK or otherway to convert transpose Columns to Rows"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 29 Jun 2005 08:36:15 -0500
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
It's not clear why you have two "MARs". If that's a typo, try this:
awk 'BEGIN{FS=OFS=",";m="JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC";s=5}
{
for (i=s; i<=NF; i++) {
print $1,$2,$3,$4,substr(m,(i-s)*3 + 1,3),$i
}
}' file
If you want the months to start at other than JAN, just change the "+ 1"
to "+ whatever" to identify the starting char number of that month in "m".
Regards,
Ed.
- Next message: alex221_at_pisem.net: "Variable value in while loop"
- Previous message: Chris F.A. Johnson: "Re: Can ksh93 do 0..9 type of syntax for loop control?"
- In reply to: Akhwashah: "AWK or otherway to convert transpose Columns to Rows"
- Next in thread: Greg Beeker: "Re: AWK or otherway to convert transpose Columns to Rows"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|