Re: AWK or otherway to convert transpose Columns to Rows

From: Ed Morton (morton_at_lsupcaemnt.com)
Date: 06/29/05


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.



Relevant Pages

  • Re: Using dates during mail merge
    ... The other thing that might be causing problems here is that, regardless of how the DATE field nested in the ASK field is formatted, the user will need to enter the date in the format set up in their regional options (or any other format where the month and day are not ambiguous. ... I was however remiss in not changing the field name from that in my data file as this added some unwelcome confusion:( ... You included 'MyDate' and 'Date2' in your ...
    (microsoft.public.word.mailmerge.fields)
  • Re: Max. Size Outlook file / split into various accounts?
    ... Properties of Persoanal Folders, in the General tab, click Advanced, look ... Anyhow if its a clean install of Outlook 2003 with a new data file +20gb ... unicode format and hence I should be safe up to 20GB? ...
    (microsoft.public.outlook.general)
  • Re: 03 versus 97/2002 version
    ... The new format is not backwards compatible so proceed at your own risk. ... File->new-outlook data file. ... dragging to the new calendar FOLDER works best. ...
    (microsoft.public.outlook)
  • Re: Using dates during mail merge
    ... If you have some other format but January eg january or JANUARY you will ... Word MVP web site http://word.mvps.org ... that in my data file as this added some unwelcome confusion:(-- ... You included 'MyDate' and 'Date2' in your ...
    (microsoft.public.word.mailmerge.fields)
  • Re: Help needed for perl rookie
    ... > Newsgroups: comp.lang.perl.misc ... However I am stuck trying to modify the ... >> example #2 and need this section of code to work with the new format. ... It reads the data file that is in this format: ...
    (comp.lang.perl.misc)