<?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: command / script help please .. in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/command-script-help-please/m-p/2589247#M32653</link>
    <description>Hi Richard:&lt;BR /&gt;&lt;BR /&gt;You go "back-to-basics".  If it's the first time (based on TOG equal to 0) then preserve the first field (awk's $1) in the variable called PREV and set TOG to 1.&lt;BR /&gt;&lt;BR /&gt;Then, test to see if the first field of the input record is the same as PREV.  If true, add the value of the third field ($3) to a counter called "T".  Otherwise, if false, then the name ($1) changed, so print the name and the (T)otal summation and set the (T)otal to the current value ($3 in the record being processed).&lt;BR /&gt;&lt;BR /&gt;At the "END", simply flush the name field (PREV) and the current (T)otal.&lt;BR /&gt;&lt;BR /&gt;Remember that outside of the tick marks surrounding 'awk', the "$1" is the file passed to the script -- as the first positional parameter.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
    <pubDate>Wed, 03 Oct 2001 17:25:01 GMT</pubDate>
    <dc:creator>James R. Ferguson</dc:creator>
    <dc:date>2001-10-03T17:25:01Z</dc:date>
    <item>
      <title>command / script help please ..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/command-script-help-please/m-p/2589229#M32635</link>
      <description>Hey everything .. I have an issue here where I have a text  file that is formatted like this:&lt;BR /&gt;the fields are&lt;BR /&gt;&lt;BR /&gt;CUSTOMER,DATE TIME FINISHED,DOLLAR AMOUNT&lt;BR /&gt;&lt;BR /&gt;customer_1,2001-10-02 05:49:40,1.98,&lt;BR /&gt;customer_1,2001-10-02 05:49:31,1.65,&lt;BR /&gt;customer_1,2001-10-02 05:49:28,23.19,&lt;BR /&gt;customer_2,2001-10-02 05:48:01,3.12,&lt;BR /&gt;customer_2,2001-10-02 05:48:00,13.95,&lt;BR /&gt;customer_3,2001-10-02 05:38:48,227.52,&lt;BR /&gt;customer_3,2001-10-02 05:38:36,213.25,&lt;BR /&gt;customer_4,2001-10-02 05:44:17,22.99,&lt;BR /&gt;customer_4,2001-10-02 05:44:44,2.69,&lt;BR /&gt;&lt;BR /&gt;And the the final output I want it to look like this for each customer: &lt;BR /&gt;CUSTOMER,DATE,TOTAL AMOUNT&lt;BR /&gt;&lt;BR /&gt;customer_1,2001-10-02,26.76&lt;BR /&gt;&lt;BR /&gt;what I am having problems with is getting the sun for each customer.&lt;BR /&gt;Any ideas?&lt;BR /&gt;&lt;BR /&gt;Richard&lt;BR /&gt;</description>
      <pubDate>Wed, 03 Oct 2001 16:01:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/command-script-help-please/m-p/2589229#M32635</guid>
      <dc:creator>someone_4</dc:creator>
      <dc:date>2001-10-03T16:01:13Z</dc:date>
    </item>
    <item>
      <title>Re: command / script help please ..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/command-script-help-please/m-p/2589230#M32636</link>
      <description>What are you using to sum these records? (perl, awk, ksh, ...??)</description>
      <pubDate>Wed, 03 Oct 2001 16:06:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/command-script-help-please/m-p/2589230#M32636</guid>
      <dc:creator>harry d brown jr</dc:creator>
      <dc:date>2001-10-03T16:06:36Z</dc:date>
    </item>
    <item>
      <title>Re: command / script help please ..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/command-script-help-please/m-p/2589231#M32637</link>
      <description>I am not using anything &lt;BR /&gt;I dont even know where to start to get the sum. &lt;BR /&gt;&lt;BR /&gt;Richard</description>
      <pubDate>Wed, 03 Oct 2001 16:08:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/command-script-help-please/m-p/2589231#M32637</guid>
      <dc:creator>someone_4</dc:creator>
      <dc:date>2001-10-03T16:08:13Z</dc:date>
    </item>
    <item>
      <title>Re: command / script help please ..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/command-script-help-please/m-p/2589232#M32638</link>
      <description>It could be a floating point to decimal rounding issue, or a variable that hasn't been initialized?&lt;BR /&gt;</description>
      <pubDate>Wed, 03 Oct 2001 16:10:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/command-script-help-please/m-p/2589232#M32638</guid>
      <dc:creator>harry d brown jr</dc:creator>
      <dc:date>2001-10-03T16:10:30Z</dc:date>
    </item>
    <item>
      <title>Re: command / script help please ..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/command-script-help-please/m-p/2589233#M32639</link>
      <description>Well the thing is how do I seperate each customer to get the totals for each customer? &lt;BR /&gt;There are more then 4 customer all with differnt but uniqe names.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 03 Oct 2001 16:12:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/command-script-help-please/m-p/2589233#M32639</guid>
      <dc:creator>someone_4</dc:creator>
      <dc:date>2001-10-03T16:12:44Z</dc:date>
    </item>
    <item>
      <title>Re: command / script help please ..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/command-script-help-please/m-p/2589234#M32640</link>
      <description>Sorry, I thought you were having rounding errors. &lt;BR /&gt;&lt;BR /&gt;awk, depending upon the data file size, would work just fine for this.</description>
      <pubDate>Wed, 03 Oct 2001 16:14:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/command-script-help-please/m-p/2589234#M32640</guid>
      <dc:creator>harry d brown jr</dc:creator>
      <dc:date>2001-10-03T16:14:23Z</dc:date>
    </item>
    <item>
      <title>Re: command / script help please ..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/command-script-help-please/m-p/2589235#M32641</link>
      <description>so what would be the command string to get the sum total of the last field for each customer ?&lt;BR /&gt;&lt;BR /&gt;richard</description>
      <pubDate>Wed, 03 Oct 2001 16:19:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/command-script-help-please/m-p/2589235#M32641</guid>
      <dc:creator>someone_4</dc:creator>
      <dc:date>2001-10-03T16:19:55Z</dc:date>
    </item>
    <item>
      <title>Re: command / script help please ..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/command-script-help-please/m-p/2589236#M32642</link>
      <description>Hi Richard&lt;BR /&gt;&lt;BR /&gt;You can use ksh to do that :&lt;BR /&gt;&lt;BR /&gt;Read you file with :&lt;BR /&gt;&lt;BR /&gt;while read line &lt;BR /&gt;do&lt;BR /&gt;  # SOME COMMANDS&lt;BR /&gt;done &amp;lt; file.name&lt;BR /&gt;&lt;BR /&gt;Now commands :&lt;BR /&gt;&lt;BR /&gt;customer=`echo $line | cut -f1 -d',' | cut -f2 -d'_'`&lt;BR /&gt;amount=`echo $line | cut -f3 -d','`&lt;BR /&gt;&lt;BR /&gt;And for sum you can use "bc" :&lt;BR /&gt;&lt;BR /&gt;total=`echo "$total + $amount" | bc`&lt;BR /&gt;&lt;BR /&gt;HTH&lt;BR /&gt;&lt;BR /&gt;Herv?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 03 Oct 2001 16:48:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/command-script-help-please/m-p/2589236#M32642</guid>
      <dc:creator>Herve BRANGIER</dc:creator>
      <dc:date>2001-10-03T16:48:12Z</dc:date>
    </item>
    <item>
      <title>Re: command / script help please ..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/command-script-help-please/m-p/2589237#M32643</link>
      <description>cat datafile|sed "s/ /,/g"|&lt;BR /&gt;awk ' BEGIN { FS=","; OFS=","; dollars = 0; cust = ""; dateof = ""; firsttime =&lt;BR /&gt;1 }&lt;BR /&gt;{&lt;BR /&gt;if ($1 == cust &amp;amp;&amp;amp; $2 == dateof ) {&lt;BR /&gt;   dollars += $4&lt;BR /&gt;} else {&lt;BR /&gt;   if ( firsttime == 0 ) {&lt;BR /&gt;      print cust, dateof, dollars&lt;BR /&gt;   }&lt;BR /&gt;   firsttime = 0&lt;BR /&gt;   cust = $1&lt;BR /&gt;   dateof = $2&lt;BR /&gt;   dollars = $4&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;END { print cust, dateof, dollars }'&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Note, that there is a "sed" that replaces the space between the date and time to a comma.</description>
      <pubDate>Wed, 03 Oct 2001 16:50:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/command-script-help-please/m-p/2589237#M32643</guid>
      <dc:creator>harry d brown jr</dc:creator>
      <dc:date>2001-10-03T16:50:33Z</dc:date>
    </item>
    <item>
      <title>Re: command / script help please ..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/command-script-help-please/m-p/2589238#M32644</link>
      <description>Hi Richard,&lt;BR /&gt;I don't know the full answer but&lt;BR /&gt;cat test | awk -F, '{s+=$3} END {print s}'&lt;BR /&gt;&lt;BR /&gt;this will print total of 3rd field.&lt;BR /&gt;&lt;BR /&gt;Sachin</description>
      <pubDate>Wed, 03 Oct 2001 16:53:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/command-script-help-please/m-p/2589238#M32644</guid>
      <dc:creator>Sachin Patel</dc:creator>
      <dc:date>2001-10-03T16:53:46Z</dc:date>
    </item>
    <item>
      <title>Re: command / script help please ..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/command-script-help-please/m-p/2589239#M32645</link>
      <description>Hey Harry . here is what I am getting &lt;BR /&gt;&lt;BR /&gt; syntax error The source line is 2.&lt;BR /&gt; The error context is&lt;BR /&gt;                 BEGIN { FS=","; OFS=","; dollars = 0; cust = ""; dateof = ""; f&lt;BR /&gt;irsttime =  &amp;gt;&amp;gt;&amp;gt; &lt;BR /&gt; &amp;lt;&amp;lt;&amp;lt; &lt;BR /&gt; awk: The statement cannot be correctly parsed.&lt;BR /&gt; The source line is 2.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 03 Oct 2001 16:58:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/command-script-help-please/m-p/2589239#M32645</guid>
      <dc:creator>someone_4</dc:creator>
      <dc:date>2001-10-03T16:58:14Z</dc:date>
    </item>
    <item>
      <title>Re: command / script help please ..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/command-script-help-please/m-p/2589240#M32646</link>
      <description>cat yourfile |&lt;BR /&gt;awk ' {&lt;BR /&gt;if ( NF &amp;lt; 2 ) next;&lt;BR /&gt;if ( NR == 1 ) {header=$0;next;}&lt;BR /&gt;&lt;BR /&gt;cus=$1;&lt;BR /&gt;split($2,array,",");&lt;BR /&gt;amount=array[2];&lt;BR /&gt;bigA[id]=bigA[id] + amount;&lt;BR /&gt;} END {&lt;BR /&gt;print header "\n";&lt;BR /&gt;for ( i in bigA ) printf("%s,%f\n",i,bigA[i]);&lt;BR /&gt;}'</description>
      <pubDate>Wed, 03 Oct 2001 17:00:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/command-script-help-please/m-p/2589240#M32646</guid>
      <dc:creator>Curtis Larson_1</dc:creator>
      <dc:date>2001-10-03T17:00:58Z</dc:date>
    </item>
    <item>
      <title>Re: command / script help please ..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/command-script-help-please/m-p/2589241#M32647</link>
      <description>Hi Richard:&lt;BR /&gt;&lt;BR /&gt;Take the script, below, and call it "my.sh".   Then, do this:&lt;BR /&gt;&lt;BR /&gt;# /.my.sh ./myinput #...where "myinput" is your data file to process:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;awk -F, '{if (TOG==0) {TOG=1;PREV=$1}};&lt;BR /&gt;{if ($1==PREV)&lt;BR /&gt;    {T=T+$3}&lt;BR /&gt;else&lt;BR /&gt;    {print T;PREV=$1;T=$3}}&lt;BR /&gt;END {print T}' $1&lt;BR /&gt;exit 0&lt;BR /&gt;#.end.&lt;BR /&gt;&lt;BR /&gt;...based on your file, the output will be:&lt;BR /&gt;&lt;BR /&gt;26.82&lt;BR /&gt;17.07&lt;BR /&gt;440.77&lt;BR /&gt;25.68&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 03 Oct 2001 17:04:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/command-script-help-please/m-p/2589241#M32647</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2001-10-03T17:04:27Z</dc:date>
    </item>
    <item>
      <title>Re: command / script help please ..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/command-script-help-please/m-p/2589242#M32648</link>
      <description>oops&lt;BR /&gt;&lt;BR /&gt;a little typo there. cus = id&lt;BR /&gt;&lt;BR /&gt;change cus=$1 to id=$1&lt;BR /&gt;or&lt;BR /&gt;bigA[id] becomes bigA[cus]&lt;BR /&gt;&lt;BR /&gt;looks like you need a bit of adjusting for your header also. but i'm sure you can deal with that.</description>
      <pubDate>Wed, 03 Oct 2001 17:04:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/command-script-help-please/m-p/2589242#M32648</guid>
      <dc:creator>Curtis Larson_1</dc:creator>
      <dc:date>2001-10-03T17:04:58Z</dc:date>
    </item>
    <item>
      <title>Re: command / script help please ..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/command-script-help-please/m-p/2589243#M32649</link>
      <description>&lt;BR /&gt;Sorry, you need to paste the script into a file and execute it, otherwise you will need to use the "\" for line continuation.</description>
      <pubDate>Wed, 03 Oct 2001 17:05:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/command-script-help-please/m-p/2589243#M32649</guid>
      <dc:creator>harry d brown jr</dc:creator>
      <dc:date>2001-10-03T17:05:25Z</dc:date>
    </item>
    <item>
      <title>Re: command / script help please ..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/command-script-help-please/m-p/2589244#M32650</link>
      <description>Hi (again) Richard:&lt;BR /&gt;&lt;BR /&gt;I really meant to show (too) the name associated with the total, like this:&lt;BR /&gt;&lt;BR /&gt;customer_1 26.82&lt;BR /&gt;customer_2 17.07&lt;BR /&gt;customer_3 440.77&lt;BR /&gt;customer_4 25.68&lt;BR /&gt;&lt;BR /&gt;So, use this:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;awk -F, '{if (TOG==0) {TOG=1;PREV=$1}};&lt;BR /&gt;{if ($1==PREV)&lt;BR /&gt;    {T=T+$3}&lt;BR /&gt;else&lt;BR /&gt;    {print PREV,T;PREV=$1;T=$3}}&lt;BR /&gt;END {print PREV,T}' $1&lt;BR /&gt;exit 0&lt;BR /&gt;#.end.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 03 Oct 2001 17:12:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/command-script-help-please/m-p/2589244#M32650</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2001-10-03T17:12:48Z</dc:date>
    </item>
    <item>
      <title>Re: command / script help please ..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/command-script-help-please/m-p/2589245#M32651</link>
      <description>LOL&lt;BR /&gt;James you read my mind .. &lt;BR /&gt;I was fixing to ask you about that. &lt;BR /&gt;Now harry and James both of yours work great. &lt;BR /&gt;But I would like to know what your script is doing. I know it is doing the job great but as far as the inside of the script can you explain what the functions are doing? &lt;BR /&gt;&lt;BR /&gt;Richard</description>
      <pubDate>Wed, 03 Oct 2001 17:15:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/command-script-help-please/m-p/2589245#M32651</guid>
      <dc:creator>someone_4</dc:creator>
      <dc:date>2001-10-03T17:15:51Z</dc:date>
    </item>
    <item>
      <title>Re: command / script help please ..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/command-script-help-please/m-p/2589246#M32652</link>
      <description>Hi Richard&lt;BR /&gt;Try this&lt;BR /&gt;-----------&lt;BR /&gt;for i in `cat report.txt |grep -v "DATE" |awk -F"," '{print $1}' |sort -u`&lt;BR /&gt;{&lt;BR /&gt;echo "\nCustomer : " $i&lt;BR /&gt;   for dollar in `cat report.txt |grep $i |awk -F"," '{sum+=$3} END {print sum}' `&lt;BR /&gt;{&lt;BR /&gt;  echo "Sum of Dollars : $dollar "&lt;BR /&gt;}&lt;BR /&gt;----&lt;BR /&gt;&lt;BR /&gt;Thanks.&lt;BR /&gt;Prashant.</description>
      <pubDate>Wed, 03 Oct 2001 17:24:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/command-script-help-please/m-p/2589246#M32652</guid>
      <dc:creator>Deshpande Prashant</dc:creator>
      <dc:date>2001-10-03T17:24:50Z</dc:date>
    </item>
    <item>
      <title>Re: command / script help please ..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/command-script-help-please/m-p/2589247#M32653</link>
      <description>Hi Richard:&lt;BR /&gt;&lt;BR /&gt;You go "back-to-basics".  If it's the first time (based on TOG equal to 0) then preserve the first field (awk's $1) in the variable called PREV and set TOG to 1.&lt;BR /&gt;&lt;BR /&gt;Then, test to see if the first field of the input record is the same as PREV.  If true, add the value of the third field ($3) to a counter called "T".  Otherwise, if false, then the name ($1) changed, so print the name and the (T)otal summation and set the (T)otal to the current value ($3 in the record being processed).&lt;BR /&gt;&lt;BR /&gt;At the "END", simply flush the name field (PREV) and the current (T)otal.&lt;BR /&gt;&lt;BR /&gt;Remember that outside of the tick marks surrounding 'awk', the "$1" is the file passed to the script -- as the first positional parameter.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 03 Oct 2001 17:25:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/command-script-help-please/m-p/2589247#M32653</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2001-10-03T17:25:01Z</dc:date>
    </item>
    <item>
      <title>Re: command / script help please ..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/command-script-help-please/m-p/2589248#M32654</link>
      <description>Hi (once again) Richard:&lt;BR /&gt;&lt;BR /&gt;Oh, I forgot to mention in my explanation of how the script works, that the '-F,' set the interfield separator for 'awk' to the comma character.  It was clear from your sample data that that was the field delimiter you chose.&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 03 Oct 2001 17:33:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/command-script-help-please/m-p/2589248#M32654</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2001-10-03T17:33:58Z</dc:date>
    </item>
  </channel>
</rss>

