Re: AWK or otherway to convert transpose Columns to Rows
From: Bruce Barnett (spamhater113+U050629081753_at_grymoire.com)
Date: 06/29/05
- Next message: Chris F.A. Johnson: "Re: BASH help please??"
- Previous message: Archie: "killing a co-process in ksh"
- In reply to: Akhwashah: "AWK or otherway to convert transpose Columns to Rows"
- Next in thread: Ed Morton: "Re: AWK or otherway to convert transpose Columns to Rows"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 29 Jun 2005 12:31:22 GMT
"Akhwashah" <akhwashah.@WARMmail.com> writes:
> 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?
You don't have to use $1, $2, etc.
some suggestions
$0 refers to the entire line. you can use split() to break
them into columns. Or you can use substr() to extract the last
part of the line, etc.
NF refers to the number of fields (columns).
So you can check the value of NF, and select printout based on that.
BTW I usually give fields names, like
Fld1=$1
Fld2=$2;
where Fld1 refers to the function of the field.
That way, when I have several different formats, I first assign values
to the fields, and then print out the fields I want to. For instance, if you have the following
>{ print $5 "\t" $8 "\t" $3 "\t" $6 "\t" $4 "\t" "NOV04" "\t" $1 "\t" $7 "}
...and if the input format changes, you have to change all of those
lines because $2 is now $3, $3 is now $4, etc. Changing this is error
prone, and can be time consuming. Instead - I assign columns to names,
and use:
printf("%s\t%s\t%s\t%s\t%s\n",
$Fld1, $Fld2, $Item, $Value, $Month)
Much easier to read and maintain....
-- Sending unsolicited commercial e-mail to this account incurs a fee of $500 per message, and acknowledges the legality of this contract.
- Next message: Chris F.A. Johnson: "Re: BASH help please??"
- Previous message: Archie: "killing a co-process in ksh"
- In reply to: Akhwashah: "AWK or otherway to convert transpose Columns to Rows"
- Next in thread: Ed Morton: "Re: AWK or otherway to convert transpose Columns to Rows"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]