<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: matrix conversion in shell scripting in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/matrix-conversion-in-shell-scripting/m-p/4721023#M660416</link>
    <description>Hi Gopi:&lt;BR /&gt;&lt;BR /&gt;Using Perl, we could do something like this:&lt;BR /&gt;&lt;BR /&gt;# cat ./mymatrix&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;use strict;&lt;BR /&gt;use warnings;&lt;BR /&gt;my ($i, $j, $square, @line);&lt;BR /&gt;undef $/;&lt;BR /&gt;$_ = &lt;DATA&gt;;&lt;BR /&gt;push @line, split;&lt;BR /&gt;$square = int(sqrt @line);&lt;BR /&gt;for ($i=0; $i&amp;lt;$square; $i++) {&lt;BR /&gt;    for ($j=0; $j&amp;lt;@line; $j+=$square) {&lt;BR /&gt;        printf "%s ", $line[$i+$j];        &lt;BR /&gt;    }&lt;BR /&gt;print "\n";&lt;BR /&gt;}&lt;BR /&gt;__DATA__&lt;BR /&gt;0 1 2 3&lt;BR /&gt;4 5 6 7&lt;BR /&gt;8 9 10 11&lt;BR /&gt;12 13 14 15&lt;BR /&gt;&lt;BR /&gt;...which when executed, transforms the maxtix in the file named DATA to:&lt;BR /&gt;&lt;BR /&gt;0 4 8 12 &lt;BR /&gt;1 5 9 13 &lt;BR /&gt;2 6 10 14 &lt;BR /&gt;3 7 11 15 &lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;/DATA&gt;</description>
    <pubDate>Thu, 02 Dec 2010 18:28:53 GMT</pubDate>
    <dc:creator>James R. Ferguson</dc:creator>
    <dc:date>2010-12-02T18:28:53Z</dc:date>
    <item>
      <title>matrix conversion in shell scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/matrix-conversion-in-shell-scripting/m-p/4721021#M660414</link>
      <description>&lt;!--!*#--&gt;Hi,&lt;BR /&gt;Today I got a requirement for matrix conversion,&lt;BR /&gt;rows to columns&lt;BR /&gt;&lt;BR /&gt;The input file for this is something like below:&lt;BR /&gt;------------------------------------------&lt;BR /&gt;VOUCHER_TYPE  BUCKET_TYPE  VOUCHER_AMT  VALIDITY &lt;BR /&gt;1000          1            0            4500      &lt;BR /&gt;1000          4            1000         10        &lt;BR /&gt;1000          5            0            1         &lt;BR /&gt;1000          7           700          1     &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;and i need the output as below:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;------------------------------------------&lt;BR /&gt;v_type b1_amt b1_val b2_amt b2_val b3_amt b3_val b4_amt b4_val b5_amt b5_val b6_amt b6_val b7_amt b7_val&lt;BR /&gt;1000 0 4500 0 0 0 0 1000 10 0 1 0 0 700 1&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I am trying to do the same with awk command and while loop but iam not getting desired output please give me some solution.&lt;BR /&gt;...Gopi&lt;BR /&gt;</description>
      <pubDate>Thu, 02 Dec 2010 16:09:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/matrix-conversion-in-shell-scripting/m-p/4721021#M660414</guid>
      <dc:creator>Gopi Kishore m</dc:creator>
      <dc:date>2010-12-02T16:09:10Z</dc:date>
    </item>
    <item>
      <title>Re: matrix conversion in shell scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/matrix-conversion-in-shell-scripting/m-p/4721022#M660415</link>
      <description>&lt;!--!*#--&gt;&amp;gt; Today I got a requirement for matrix&lt;BR /&gt;&amp;gt; conversion, rows to columns&lt;BR /&gt;&lt;BR /&gt;Congratulations.&lt;BR /&gt;&lt;BR /&gt;&amp;gt; and i need the output as below:&lt;BR /&gt;&lt;BR /&gt;This must be some new definition of "rows to&lt;BR /&gt;columns", because you seem to be converting&lt;BR /&gt;a four-by-four array of values into a set of&lt;BR /&gt;fifteen different values (in no obvious&lt;BR /&gt;order, with no obvious structure).&lt;BR /&gt;&lt;BR /&gt;&amp;gt; [...] please give me some solution.&lt;BR /&gt;&lt;BR /&gt;Please provide a problem description which&lt;BR /&gt;makes more sense.&lt;BR /&gt;&lt;BR /&gt;Then send money.</description>
      <pubDate>Thu, 02 Dec 2010 18:01:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/matrix-conversion-in-shell-scripting/m-p/4721022#M660415</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2010-12-02T18:01:12Z</dc:date>
    </item>
    <item>
      <title>Re: matrix conversion in shell scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/matrix-conversion-in-shell-scripting/m-p/4721023#M660416</link>
      <description>Hi Gopi:&lt;BR /&gt;&lt;BR /&gt;Using Perl, we could do something like this:&lt;BR /&gt;&lt;BR /&gt;# cat ./mymatrix&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;use strict;&lt;BR /&gt;use warnings;&lt;BR /&gt;my ($i, $j, $square, @line);&lt;BR /&gt;undef $/;&lt;BR /&gt;$_ = &lt;DATA&gt;;&lt;BR /&gt;push @line, split;&lt;BR /&gt;$square = int(sqrt @line);&lt;BR /&gt;for ($i=0; $i&amp;lt;$square; $i++) {&lt;BR /&gt;    for ($j=0; $j&amp;lt;@line; $j+=$square) {&lt;BR /&gt;        printf "%s ", $line[$i+$j];        &lt;BR /&gt;    }&lt;BR /&gt;print "\n";&lt;BR /&gt;}&lt;BR /&gt;__DATA__&lt;BR /&gt;0 1 2 3&lt;BR /&gt;4 5 6 7&lt;BR /&gt;8 9 10 11&lt;BR /&gt;12 13 14 15&lt;BR /&gt;&lt;BR /&gt;...which when executed, transforms the maxtix in the file named DATA to:&lt;BR /&gt;&lt;BR /&gt;0 4 8 12 &lt;BR /&gt;1 5 9 13 &lt;BR /&gt;2 6 10 14 &lt;BR /&gt;3 7 11 15 &lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;/DATA&gt;</description>
      <pubDate>Thu, 02 Dec 2010 18:28:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/matrix-conversion-in-shell-scripting/m-p/4721023#M660416</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2010-12-02T18:28:53Z</dc:date>
    </item>
    <item>
      <title>Re: matrix conversion in shell scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/matrix-conversion-in-shell-scripting/m-p/4721024#M660417</link>
      <description>&lt;!--!*#--&gt;Hi (again):&lt;BR /&gt;&lt;BR /&gt;Use this version and you can pass any file as long as the number of rows equals the number of columns.  That is, the matrix is a square.&lt;BR /&gt;&lt;BR /&gt;# cat ./mymatrix&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;use strict;&lt;BR /&gt;use warnings;&lt;BR /&gt;my ($i, $j, $square, @line);&lt;BR /&gt;while (&amp;lt;&amp;gt;) {&lt;BR /&gt;    chomp;&lt;BR /&gt;    push @line, split;&lt;BR /&gt;}&lt;BR /&gt;$square = int(sqrt @line);&lt;BR /&gt;for ($i=0; $i&amp;lt;$square; $i++) {&lt;BR /&gt;    for ($j=0; $j&amp;lt;@line; $j+=$square) {&lt;BR /&gt;        printf "%s ", $line[$i+$j];        &lt;BR /&gt;    }&lt;BR /&gt;print "\n";&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;...run as:&lt;BR /&gt;&lt;BR /&gt;# ./mymatrix file&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 02 Dec 2010 18:56:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/matrix-conversion-in-shell-scripting/m-p/4721024#M660417</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2010-12-02T18:56:11Z</dc:date>
    </item>
    <item>
      <title>Re: matrix conversion in shell scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/matrix-conversion-in-shell-scripting/m-p/4721025#M660418</link>
      <description>&lt;!--!*#--&gt;Hi (again):&lt;BR /&gt;&lt;BR /&gt;Actually, we can invert rectangular matrices with just a slight modification:&lt;BR /&gt;&lt;BR /&gt;# cat ./mymatrix&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;use strict;&lt;BR /&gt;use warnings;&lt;BR /&gt;my ($i, $j, $seen, $side, @line);&lt;BR /&gt;while (&amp;lt;&amp;gt;) {&lt;BR /&gt;    chomp;&lt;BR /&gt;    push @line, split;&lt;BR /&gt;    if (! $seen) {&lt;BR /&gt;        $seen++;&lt;BR /&gt;        $side = @line; #...nbr elements in 1st row...    &lt;BR /&gt;    }&lt;BR /&gt;}&lt;BR /&gt;for ($i=0; $i&amp;lt;$side; $i++) {&lt;BR /&gt;    for ($j=0; $j&amp;lt;@line; $j+=$side) {&lt;BR /&gt;        printf "%s ", $line[$i+$j];        &lt;BR /&gt;    }&lt;BR /&gt;print "\n";&lt;BR /&gt;}&lt;BR /&gt;1;&lt;BR /&gt;&lt;BR /&gt;Now you can have transformations like:&lt;BR /&gt;&lt;BR /&gt;1 2 3&lt;BR /&gt;4 5 6&lt;BR /&gt;7 8 9&lt;BR /&gt;&lt;BR /&gt;to:&lt;BR /&gt;&lt;BR /&gt;1 4 7 &lt;BR /&gt;2 5 8 &lt;BR /&gt;3 6 9&lt;BR /&gt;&lt;BR /&gt;and:&lt;BR /&gt;&lt;BR /&gt;1 2 3 4 5&lt;BR /&gt;6 7 8 9 0&lt;BR /&gt;&lt;BR /&gt;to:&lt;BR /&gt;&lt;BR /&gt;1 6 &lt;BR /&gt;2 7 &lt;BR /&gt;3 8 &lt;BR /&gt;4 9 &lt;BR /&gt;5 0 &lt;BR /&gt;&lt;BR /&gt;and:&lt;BR /&gt;&lt;BR /&gt;1 2&lt;BR /&gt;3 4&lt;BR /&gt;5 6&lt;BR /&gt;7 8&lt;BR /&gt;9 0&lt;BR /&gt;&lt;BR /&gt;to:&lt;BR /&gt;&lt;BR /&gt;1 3 5 7 9 &lt;BR /&gt;2 4 6 8 0 &lt;BR /&gt;&lt;BR /&gt;Regards and Enjoy!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Thu, 02 Dec 2010 22:13:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/matrix-conversion-in-shell-scripting/m-p/4721025#M660418</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2010-12-02T22:13:13Z</dc:date>
    </item>
    <item>
      <title>Re: matrix conversion in shell scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/matrix-conversion-in-shell-scripting/m-p/4721026#M660419</link>
      <description>Nice generic solutions.&lt;BR /&gt;The GAWK manual specificically has a rotate array example:&lt;BR /&gt;&lt;A href="http://www.math.utah.edu/docs/info/gawk_12.html#SEC121" target="_blank"&gt;http://www.math.utah.edu/docs/info/gawk_12.html#SEC121&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;But this is a more specific example.&lt;BR /&gt;&lt;BR /&gt;Here is some awk that will do the job...&lt;BR /&gt;&lt;BR /&gt;----------------&lt;BR /&gt;NR &amp;gt; 1 {&lt;BR /&gt;  amt[$2] = $3;&lt;BR /&gt;  val[$2] = $4;&lt;BR /&gt;  if ($2 &amp;gt; values) values = $2;&lt;BR /&gt;  type = $1;&lt;BR /&gt;}&lt;BR /&gt;END {&lt;BR /&gt;    head = "type";&lt;BR /&gt;    line = type;&lt;BR /&gt;    for (i = 1; i &amp;lt;= values; i++) {&lt;BR /&gt;      head = head " amt" i " val" i&lt;BR /&gt;      a = v = 0;&lt;BR /&gt;      if (i in val) { a = amt[i]; v = val[i] }  &lt;BR /&gt;      line = line " " a " " v;&lt;BR /&gt;    }&lt;BR /&gt;    print head;&lt;BR /&gt;    print line;&lt;BR /&gt;}&lt;BR /&gt;---------&lt;BR /&gt;&lt;BR /&gt;So for each line execpt the first it sticks the critical columns in arrays indexed by the 'bucket_type' column.&lt;BR /&gt;At the end it builds a header line and data line for each present type number, filling out with zeroes otherwise.&lt;BR /&gt;&lt;BR /&gt;Now I suspect that the usage is more involved. &lt;BR /&gt;For example more 'voucher_types', each together.&lt;BR /&gt;In that case you'd need to print at the end, but also at each voucher type change.&lt;BR /&gt;So you need a new header, when the number of columns change? I don't know.&lt;BR /&gt;The code below gives a more complex example handling multiple voucher_types in a single file.&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;Hein&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;NR == 1 { next }&lt;BR /&gt;$1 != type {&lt;BR /&gt;  if (values) {&lt;BR /&gt;    head = "type";&lt;BR /&gt;    line = type;&lt;BR /&gt;    for (i = 1; i&amp;lt;= values; i++) {&lt;BR /&gt;      head = head " amt" i " val" i&lt;BR /&gt;      a = v = 0;&lt;BR /&gt;      if (i in val) { a = amt[i]; v = val[i]; delete amt[i]; delete val[i] }  &lt;BR /&gt;      line = line " " a " " v;&lt;BR /&gt;    }&lt;BR /&gt;    print head;&lt;BR /&gt;    print line;&lt;BR /&gt;    values = 0; &lt;BR /&gt;  }&lt;BR /&gt;  type = $1;&lt;BR /&gt;}&lt;BR /&gt;$1 == type {&lt;BR /&gt;  amt[$2] = $3;&lt;BR /&gt;  val[$2] = $4;&lt;BR /&gt;  if ($2 &amp;gt; values) values = $2;&lt;BR /&gt;}&lt;BR /&gt;END {&lt;BR /&gt;    head = "type";&lt;BR /&gt;    line = type;&lt;BR /&gt;    for (i = 1; i &amp;lt;= values; i++) {&lt;BR /&gt;      head = head " amt" i " val" i&lt;BR /&gt;      a = v = 0;&lt;BR /&gt;      if (i in val) { a = amt[i]; v = val[i]; delete amt[i]; delete val[i] }  &lt;BR /&gt;      line = line " " a " " v;&lt;BR /&gt;    }&lt;BR /&gt;    print head;&lt;BR /&gt;    print line;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 03 Dec 2010 05:47:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/matrix-conversion-in-shell-scripting/m-p/4721026#M660419</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2010-12-03T05:47:01Z</dc:date>
    </item>
  </channel>
</rss>

