<?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: Scripting help in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-help/m-p/4952911#M413992</link>
    <description>Thanks all, I have many choices to go with now.  &lt;BR /&gt;&lt;BR /&gt;Have tested some and they look fine.&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;</description>
    <pubDate>Tue, 17 Jan 2006 10:00:06 GMT</pubDate>
    <dc:creator>Paul Thomson_2</dc:creator>
    <dc:date>2006-01-17T10:00:06Z</dc:date>
    <item>
      <title>Scripting help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-help/m-p/4952902#M413983</link>
      <description>Hi&lt;BR /&gt;&lt;BR /&gt;I have a file containing two columns.&lt;BR /&gt;Column 1 = text&lt;BR /&gt;Column 2 = numbers&lt;BR /&gt;&lt;BR /&gt;I wish to read the file a line at a time and as long as the value of column 1 is the same, add the values of column 2 together.  &lt;BR /&gt;&lt;BR /&gt;Col 1 contains hostnames, so as long as the hostname remains the same, add col 2 together.&lt;BR /&gt;&lt;BR /&gt;Im getting a little stuck on the scripting for this.&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;</description>
      <pubDate>Tue, 17 Jan 2006 09:19:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-help/m-p/4952902#M413983</guid>
      <dc:creator>Paul Thomson_2</dc:creator>
      <dc:date>2006-01-17T09:19:13Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-help/m-p/4952903#M413984</link>
      <description>Please, this need more expalnation. Col 1 is a text and you cannot add it to col 2 a number. unless col 1 is a string which could be number or text.&lt;BR /&gt;&lt;BR /&gt;Please, shed more light. Do you mean we should apend col 2 to 1 after?</description>
      <pubDate>Tue, 17 Jan 2006 09:29:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-help/m-p/4952903#M413984</guid>
      <dc:creator>Lolupee</dc:creator>
      <dc:date>2006-01-17T09:29:35Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-help/m-p/4952904#M413985</link>
      <description>Hi &lt;BR /&gt;it a flat file containing information such as &lt;BR /&gt;&lt;BR /&gt;column 1         column 2&lt;BR /&gt;&lt;BR /&gt;server1          10&lt;BR /&gt;server1          15&lt;BR /&gt;server1          20&lt;BR /&gt;server1          40&lt;BR /&gt;server2          19&lt;BR /&gt;server2          19&lt;BR /&gt;&lt;BR /&gt;In this example, I would like to read the file line by line and as long as column 1 is equal to server1 add the numbers from column 2 making a total of 85 in this example.  I could then write server1 and the total figure to another file for example.&lt;BR /&gt;</description>
      <pubDate>Tue, 17 Jan 2006 09:32:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-help/m-p/4952904#M413985</guid>
      <dc:creator>Paul Thomson_2</dc:creator>
      <dc:date>2006-01-17T09:32:52Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-help/m-p/4952905#M413986</link>
      <description>Paul,&lt;BR /&gt;no doubt the perl experts are going to produce a one-liner!&lt;BR /&gt;However:&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;oldhost=""&lt;BR /&gt;while read host number&lt;BR /&gt;do&lt;BR /&gt;if [ "$host" = "$oldhost" ]&lt;BR /&gt;then&lt;BR /&gt;counted=`expr $counted + $number`&lt;BR /&gt;else&lt;BR /&gt;echo $oldhost $counted&lt;BR /&gt;oldhost=$host&lt;BR /&gt;counted=$number&lt;BR /&gt;fi&lt;BR /&gt;done &amp;lt; a.lis&lt;BR /&gt;&lt;BR /&gt;Should work as long as there is one additional empty line at the end of the a.lis input file.</description>
      <pubDate>Tue, 17 Jan 2006 09:40:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-help/m-p/4952905#M413986</guid>
      <dc:creator>Peter Godron</dc:creator>
      <dc:date>2006-01-17T09:40:26Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-help/m-p/4952906#M413987</link>
      <description>Assuming your colums are separated by white space&lt;BR /&gt;&lt;BR /&gt;# perl -nle'sub z{print"$p:$s";$s=0}($h,$n)=(/^\s*(\S+)\s+(\d+)/);$h eq$p or z;$p=$h;$s+=$n}END{z' file&lt;BR /&gt;&lt;BR /&gt;Demo:&lt;BR /&gt;&lt;BR /&gt;lt09:/home/merijn 101 &amp;gt; cat &amp;gt;xx.txt&lt;BR /&gt;a 1&lt;BR /&gt; a 4&lt;BR /&gt;a 1&lt;BR /&gt;&lt;BR /&gt;b 2&lt;BR /&gt;b 2&lt;BR /&gt;c 7&lt;BR /&gt;d 8&lt;BR /&gt;d 0&lt;BR /&gt;lt09:/home/merijn 102 &amp;gt; perl -nle'sub z{print"$p:$s";$s=0}($h,$n)=(/^\s*(\S+)\s+(\d+)/);$h eq$p or z;$p=$h;$s+=$n}END{z' xx.txt&lt;BR /&gt;:&lt;BR /&gt;a:6&lt;BR /&gt;:0&lt;BR /&gt;b:4&lt;BR /&gt;c:7&lt;BR /&gt;d:8&lt;BR /&gt;lt09:/home/merijn 103 &amp;gt;&lt;BR /&gt;&lt;BR /&gt;Enjoy, Have FUN! H.Merijn&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 17 Jan 2006 09:42:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-help/m-p/4952906#M413987</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2006-01-17T09:42:42Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-help/m-p/4952907#M413988</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;# perl -nalF -e '$prev=$F[0] if !defined($prev);if ($F[0] eq $prev) {$i++} else {pr&lt;BR /&gt;int "$prev=$i";$i=1};$prev=$F[0];END{print "$prev=$i"}' file&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 17 Jan 2006 09:45:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-help/m-p/4952907#M413988</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-01-17T09:45:19Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-help/m-p/4952908#M413989</link>
      <description>It's not PERL, and it's not very pretty, but it works and does not need a blank line at the end.&lt;BR /&gt;&lt;BR /&gt;# cat testscript&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;ITER=1&lt;BR /&gt;NUMTOT=0&lt;BR /&gt;while read HOST NUM&lt;BR /&gt;do&lt;BR /&gt;if [[ ${HOSTB} = ${HOST} || ${ITER} = 1 ]] ; then&lt;BR /&gt;   ((NUMTOT=$NUMTOT+$NUM))&lt;BR /&gt;   HOSTB=$HOST&lt;BR /&gt;   ITER=2&lt;BR /&gt;else&lt;BR /&gt;   echo "The total for ${HOSTB} is ${NUMTOT}"&lt;BR /&gt;   NUMTOT=0&lt;BR /&gt;   ((NUMTOT=$NUMTOT+$NUM))&lt;BR /&gt;   HOSTB=$HOST&lt;BR /&gt;fi&lt;BR /&gt;done &amp;lt; testfile&lt;BR /&gt;echo "The total for ${HOSTB} is ${NUMTOT}" &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 17 Jan 2006 09:48:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-help/m-p/4952908#M413989</guid>
      <dc:creator>Patrick Wallek</dc:creator>
      <dc:date>2006-01-17T09:48:16Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-help/m-p/4952909#M413990</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;#!/opt/perl/bin/perl -w&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;my %hash = ();&lt;BR /&gt;&lt;BR /&gt;my $file_in = "/tmp/file_in";&lt;BR /&gt;my $file_out = "/tmp/file_out";&lt;BR /&gt;&lt;BR /&gt;open (IN, "&amp;lt;$file_in" ) or die "cannot open file $file_in";&lt;BR /&gt;open (OUT, "&amp;gt;$file_out") or die "cannot open file $file_out";&lt;BR /&gt;&lt;BR /&gt;while (my $line = &lt;IN&gt;){&lt;BR /&gt;        chomp($line);&lt;BR /&gt;        my ($host, $num) = split(/\s+/,$line);&lt;BR /&gt;        print "$host\n";&lt;BR /&gt;        $hash{$host}[0] += $num;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;foreach my $key (sort keys %hash){&lt;BR /&gt;        print OUT "$key $hash{$key}[0]\n";&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;/IN&gt;</description>
      <pubDate>Tue, 17 Jan 2006 09:57:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-help/m-p/4952909#M413990</guid>
      <dc:creator>Fat Scrape</dc:creator>
      <dc:date>2006-01-17T09:57:01Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-help/m-p/4952910#M413991</link>
      <description>Mine cant be better. You already have more than enough.&lt;BR /&gt;</description>
      <pubDate>Tue, 17 Jan 2006 09:59:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-help/m-p/4952910#M413991</guid>
      <dc:creator>Lolupee</dc:creator>
      <dc:date>2006-01-17T09:59:29Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-help/m-p/4952911#M413992</link>
      <description>Thanks all, I have many choices to go with now.  &lt;BR /&gt;&lt;BR /&gt;Have tested some and they look fine.&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;</description>
      <pubDate>Tue, 17 Jan 2006 10:00:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-help/m-p/4952911#M413992</guid>
      <dc:creator>Paul Thomson_2</dc:creator>
      <dc:date>2006-01-17T10:00:06Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-help/m-p/4952912#M413993</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;obviously &lt;BR /&gt;&lt;BR /&gt;/tmp/file_in is:&lt;BR /&gt;&lt;BR /&gt;server1 10&lt;BR /&gt;server1 15&lt;BR /&gt;server1 20&lt;BR /&gt;server1 40&lt;BR /&gt;server2 19&lt;BR /&gt;server2 19&lt;BR /&gt;&lt;BR /&gt;/tmp/file_out is:&lt;BR /&gt;&lt;BR /&gt;server1 85&lt;BR /&gt;server2 38&lt;BR /&gt;&lt;BR /&gt;Regards,</description>
      <pubDate>Tue, 17 Jan 2006 10:01:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-help/m-p/4952912#M413993</guid>
      <dc:creator>Fat Scrape</dc:creator>
      <dc:date>2006-01-17T10:01:34Z</dc:date>
    </item>
  </channel>
</rss>

