<?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: awk help:  summarize list when column X changes value in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/awk-help-summarize-list-when-column-x-changes-value/m-p/3683303#M102922</link>
    <description>Hi&lt;BR /&gt;&lt;BR /&gt;Keep it simple&lt;BR /&gt;&lt;BR /&gt;cat tmp/in|cut -f1 -d " "|sort -u|&lt;BR /&gt;while read line&lt;BR /&gt;do&lt;BR /&gt; let xx=$(grep $line tmp/in|wc -l)&lt;BR /&gt; echo $line has $xx $(grep $line tmp/in|&lt;BR /&gt; head -n 1|cut -f5-6 -d" ") disks&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;tmp/in is data file containing list shown&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;               Steve Steel</description>
    <pubDate>Fri, 02 Dec 2005 10:43:56 GMT</pubDate>
    <dc:creator>Steve Steel</dc:creator>
    <dc:date>2005-12-02T10:43:56Z</dc:date>
    <item>
      <title>awk help:  summarize list when column X changes value</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-help-summarize-list-when-column-x-changes-value/m-p/3683301#M102920</link>
      <description>This is the output from the EMC symdisk command:&lt;BR /&gt;&lt;BR /&gt;DA-7B  07B    D   1 SEAGATE    CUDA180        24   173017      450   173145&lt;BR /&gt;DA-7B  07B    D   2 SEAGATE    CUDA180        20   173017      386   173145&lt;BR /&gt;DA-7B  07B    D   3 SEAGATE    CUDA180        20   173017      386   173145&lt;BR /&gt;DA-8B  08B    C   5 SEAGATE    CUDA180        20   173017      386   173145&lt;BR /&gt;DA-8B  08B    C   8 SEAGATE    CUDA180        20   173017      386   173145&lt;BR /&gt;DA-8B  08B    C   9 SEAGATE    CUDA180        20   173017      386   173145&lt;BR /&gt;DA-8B  08B    D   0 SEAGATE    CUDA180        21   173017      383   173145&lt;BR /&gt;DA-8B  08B    D   1 SEAGATE    CUDA180        25   173017     5946   173145&lt;BR /&gt;DA-8B  08B    D   2 SEAGATE    CUDA180        21   173017      383   173145&lt;BR /&gt;DA-8B  08B    D   3 SEAGATE    CUDA180        20   173017      386   173145&lt;BR /&gt;DA-9B  09B    C   1 SEAGATE    CUDA180        21   173017      383   173145&lt;BR /&gt;DA-9B  09B    C   2 SEAGATE    CUDA180        20   173017      386   173145&lt;BR /&gt;DA-9B  09B    C   3 SEAGATE    CUDA180        20   173017      386   173145&lt;BR /&gt;DA-9B  09B    C   4 SEAGATE    CUDA180        20   173017      386   173145&lt;BR /&gt;DA-9B  09B    C   5 SEAGATE    CUDA180        20   173017      386   173145&lt;BR /&gt;DA-9B  09B    C   8 SEAGATE    CUDA180        20   173017      386   173145&lt;BR /&gt;DA-9B  09B    C   9 SEAGATE    CUDA180        20   173017      386   173145&lt;BR /&gt;DA-10B 10B    C   4 SEAGATE    CUDA180        20   173017      386   173145&lt;BR /&gt;DA-10B 10B    C   5 SEAGATE    CUDA180        20   173017      386   173145&lt;BR /&gt;DA-10B 10B    C   8 SEAGATE    CUDA180        20   173017      386   173145&lt;BR /&gt;DA-10B 10B    C   9 SEAGATE    CUDA180        20   173017      386   173145&lt;BR /&gt;DA-10B 10B    D   0 SEAGATE    CUDA180        21   173017      383   173145&lt;BR /&gt;DA-10B 10B    D   1 SEAGATE    CUDA180        21   173017      383   173145&lt;BR /&gt;DA-10B 10B    D   2 SEAGATE    CUDA180        20   173017      386   173145&lt;BR /&gt;DA-10B 10B    D   3 SEAGATE    CUDA180        20   173017      386   173145&lt;BR /&gt;DA-10B 10B    D   4 SEAGATE    CUDA180        20   173017      386   173145&lt;BR /&gt;&lt;BR /&gt;I want to summarize when the "DA" changes.  &lt;BR /&gt;&lt;BR /&gt;I want to say:&lt;BR /&gt;DA-07B has 4 x SEAGATE CUDA180 Disks.&lt;BR /&gt;DA-08b has 4 x .. etc.&lt;BR /&gt;&lt;BR /&gt;How do i do that in "awk"?  Is there some way to say "when $1 changes, count up.."?  Or do I have to save the value and check every time, etc.?</description>
      <pubDate>Fri, 02 Dec 2005 10:22:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-help-summarize-list-when-column-x-changes-value/m-p/3683301#M102920</guid>
      <dc:creator>Stuart Abramson</dc:creator>
      <dc:date>2005-12-02T10:22:33Z</dc:date>
    </item>
    <item>
      <title>Re: awk help:  summarize list when column X changes value</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-help-summarize-list-when-column-x-changes-value/m-p/3683302#M102921</link>
      <description>Hi Stuart:&lt;BR /&gt;&lt;BR /&gt;Try this:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/awk -f&lt;BR /&gt;{if (FIRST!=1) {FIRST=1;LAST=$1}}&lt;BR /&gt;{if ($1!=LAST) {print LAST," count = ",CNT;CNT=0;LAST=$1}}&lt;BR /&gt;{print;CNT++}&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Fri, 02 Dec 2005 10:43:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-help-summarize-list-when-column-x-changes-value/m-p/3683302#M102921</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2005-12-02T10:43:51Z</dc:date>
    </item>
    <item>
      <title>Re: awk help:  summarize list when column X changes value</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-help-summarize-list-when-column-x-changes-value/m-p/3683303#M102922</link>
      <description>Hi&lt;BR /&gt;&lt;BR /&gt;Keep it simple&lt;BR /&gt;&lt;BR /&gt;cat tmp/in|cut -f1 -d " "|sort -u|&lt;BR /&gt;while read line&lt;BR /&gt;do&lt;BR /&gt; let xx=$(grep $line tmp/in|wc -l)&lt;BR /&gt; echo $line has $xx $(grep $line tmp/in|&lt;BR /&gt; head -n 1|cut -f5-6 -d" ") disks&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;tmp/in is data file containing list shown&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;               Steve Steel</description>
      <pubDate>Fri, 02 Dec 2005 10:43:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-help-summarize-list-when-column-x-changes-value/m-p/3683303#M102922</guid>
      <dc:creator>Steve Steel</dc:creator>
      <dc:date>2005-12-02T10:43:56Z</dc:date>
    </item>
    <item>
      <title>Re: awk help:  summarize list when column X changes value</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-help-summarize-list-when-column-x-changes-value/m-p/3683304#M102923</link>
      <description>For a simple count where the disk type doesn't matter-&lt;BR /&gt;cut -c1 yourfile | sort | uniq -c&lt;BR /&gt; &lt;BR /&gt;Perl can provide a more complete routine-&lt;BR /&gt;perl -an -e '$tot{$F[0]}{"$F[4] $F[5]"}++;END {for $DA (sort keys %tot) { for $dsk (sort keys %{$tot{$DA}}) { print "$DA has $tot{$DA}{$dsk} $dsk Disks.\n";}}}' yourfile&lt;BR /&gt; &lt;BR /&gt;HTH&lt;BR /&gt; &lt;BR /&gt;-- Rod Hills</description>
      <pubDate>Fri, 02 Dec 2005 10:58:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-help-summarize-list-when-column-x-changes-value/m-p/3683304#M102923</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2005-12-02T10:58:43Z</dc:date>
    </item>
    <item>
      <title>Re: awk help:  summarize list when column X changes value</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-help-summarize-list-when-column-x-changes-value/m-p/3683305#M102924</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;just shorter and without awk:&lt;BR /&gt;cut -f1 -d " " /tmp/x | sort | uniq -c&lt;BR /&gt;&lt;BR /&gt;mfG nik</description>
      <pubDate>Fri, 02 Dec 2005 11:05:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-help-summarize-list-when-column-x-changes-value/m-p/3683305#M102924</guid>
      <dc:creator>Peter Nikitka</dc:creator>
      <dc:date>2005-12-02T11:05:20Z</dc:date>
    </item>
    <item>
      <title>Re: awk help:  summarize list when column X changes value</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-help-summarize-list-when-column-x-changes-value/m-p/3683306#M102925</link>
      <description>Hi Stuart:&lt;BR /&gt;&lt;BR /&gt;BTW, you never evaluated the responses in your thread below and I would like to know if you found them helpful.  Thanks.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=976274" target="_blank"&gt;http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=976274&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Fri, 02 Dec 2005 11:38:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-help-summarize-list-when-column-x-changes-value/m-p/3683306#M102925</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2005-12-02T11:38:32Z</dc:date>
    </item>
    <item>
      <title>Re: awk help:  summarize list when column X changes value</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-help-summarize-list-when-column-x-changes-value/m-p/3683307#M102926</link>
      <description>Stuart,&lt;BR /&gt;&lt;BR /&gt;How about this awk construct:&lt;BR /&gt;&lt;BR /&gt;awk '/^DA-[0-9]*B/{line=$5" "$6;if(NF==1){curr=$1;count[curr]++} else{if(curr==$1)count[curr]++;else{curr=$1;count[curr]++}}} END{for(i in count) print i " has", count[i] " x " line " Disks"}' &lt;INPUTFILE&gt;&lt;BR /&gt;&lt;BR /&gt;cheers!&lt;/INPUTFILE&gt;</description>
      <pubDate>Fri, 02 Dec 2005 12:58:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-help-summarize-list-when-column-x-changes-value/m-p/3683307#M102926</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2005-12-02T12:58:41Z</dc:date>
    </item>
    <item>
      <title>Re: awk help:  summarize list when column X changes value</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-help-summarize-list-when-column-x-changes-value/m-p/3683308#M102927</link>
      <description>Matter of fact the code is easier to understand if put into its own script:&lt;BR /&gt;&lt;BR /&gt;=====================myawkscript=======================&lt;BR /&gt;/^DA-[0-9]*B/ {&lt;BR /&gt;     line=$5" "$6&lt;BR /&gt;     if ((NF==1)||(curr==$1)) {&lt;BR /&gt;        curr=$1&lt;BR /&gt;        count[curr]++&lt;BR /&gt;     }&lt;BR /&gt;     else {&lt;BR /&gt;           curr=$1&lt;BR /&gt;           count[curr]++&lt;BR /&gt;     }&lt;BR /&gt;}&lt;BR /&gt;END{for(i in count) printf("%s has %d x %s Disks\n", i, count[i], line)}&lt;BR /&gt;=======================================================&lt;BR /&gt;&lt;BR /&gt;# symdisk | awk -f myawkscript&lt;BR /&gt;&lt;BR /&gt;cheers!&lt;BR /&gt;</description>
      <pubDate>Fri, 02 Dec 2005 14:43:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-help-summarize-list-when-column-x-changes-value/m-p/3683308#M102927</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2005-12-02T14:43:15Z</dc:date>
    </item>
  </channel>
</rss>

