Sponsored Content
Full Discussion: awk to sum in Loop
Contact Us Post Here to Contact Site Administrators and Moderators awk to sum in Loop Post 302963145 by MOHANP12 on Thursday 24th of December 2015 10:57:14 AM
Old 12-24-2015
My OS is AIX 7 and ksh shell

Input data

Code:
ISA*00*          *00*          *ZZ*ABCCOM         *ZZ*99999999       *040315*1005*U*00401*004075123*0*P*:
GS*HP*ABCCOM*01017*20110315*1005*1*X*004010X091A1
ST*835*07504123
BPR*H*5.75*C*NON************20110315
CLP*999999*4*25.95*0*25.95*13*0000000555555555*11
CAS*CR*18*25.95*0
REF*6R*999999
CLP*888888*4*162.13*0*162.13*MC*0000000456789123*11
SVC*ZZ:M151000:F0*162.13*0**1.9
DTM*472*20020920
CAS*CO*29*162.13*0*42*0*0
CLP*111111*2*56.52*18.88*0*13*0000000644444444*53
CLP*121212*4*56.52*0*0*13*0000000646464640*53
CLP*333333*1*74.61*59.69*14.92*13*0000000688888888*55
REF*6R*333333
CLP*777777*25*136.9*0*0*13*0000000622222222*53
DTM*472*20030911
CAS*PI*104*136.72*0
CAS*CO*42*0.18*0
NM1*82*2*ABTHSOLUTE HELP*****FI*346608640
REF*F8*A76B04054
SVC*HC:H0004:HF:H9*-86.76*-86.76**-4
DTM*472*20110210
CAS*CR*22*0*0*42*0*0
CAS*OA*22*0*0
REF*6R*090909
LQ*HE*MA92
SE*93*07504123
GE*1*1
IEA*1*004075123


Output File



ISA*00*          *00*          *ZZ*ABCCOM         *ZZ*99999999       *040315*1005*U*00401*004075123*0*P*:
GS*HP*ABCCOM*01017*20110315*1005*1*X*004010X091A1
ST*835*07504123
BPR*H*5.75*C*NON************20110315
CLP*999999*4*25.95*0*25.95*13*0000000555555555*11
CAS*CR*18*25.95*0
REF*6R*999999
CLP*888888*4*162.13*0*162.13*MC*0000000456789123*11
SVC*ZZ:M151000:F0*162.13*0**1.9
DTM*472*20020920
CAS*CO*29*162.13*0*42*0*0
CLP*111111*2*56.52*18.88*0*13*0000000644444444*53
SE*93*07504123
ST*835*07504123
BPR*H*5.75*C*NON************20110315
CLP*121212*4*56.52*0*0*13*0000000646464640*53
CLP*333333*1*74.61*59.69*14.92*13*0000000688888888*55
REF*6R*333333
CLP*777777*25*136.9*0*0*13*0000000622222222*53
DTM*472*20030911
CAS*PI*104*136.72*0
CAS*CO*42*0.18*0
NM1*82*2*ABTHSOLUTE HELP*****FI*346608640
REF*F8*A76B04054
SVC*HC:H0004:HF:H9*-86.76*-86.76**-4
DTM*472*20110210
CAS*CR*22*0*0*42*0*0
CAS*OA*22*0*0
REF*6R*090909
LQ*HE*MA92
SE*93*07504123
GE*1*1
IEA*1*004075123

Thanks in advance

Don CLP04 means input file have number of rows in which row which start with CLP and * is field separator then value after 4th * is CLP 04
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

While loop - The sum seems to be local

Hi, I am trying to extracting the sum of all varibles listed in a file. The code is as follows ##### FILE1 ######## Value1:2 Value2:2 Value3:6 Value4:5 ##### shell script ###### #!/bin/sh total=0 (2 Replies)
Discussion started by: eagercyber
2 Replies

2. Shell Programming and Scripting

Sum with awk

Hi,consider this fields, $1 $2 $3 981 0 1 984 0 4 985 1 0 987 0 2 990 0 0 993 0 3 995 2 0 996 0 1 999 0 4 for each occurence of zero in column $2 and $3 I need to sum $1 fields, so for example, in this piece of code the result of $1 is 8910. I'm sure... (2 Replies)
Discussion started by: cv313x
2 Replies

3. Shell Programming and Scripting

scripting/awk help : awk sum output is not comming in regular format. Pls advise.

Hi Experts, I am adding a column of numbers with awk , however not getting correct output: # awk '{sum+=$1} END {print sum}' datafile 2.15291e+06 How can I getthe output like : 2152910 Thank you.. # awk '{sum+=$1} END {print sum}' datafile 2.15079e+06 (3 Replies)
Discussion started by: rveri
3 Replies

4. Shell Programming and Scripting

Sum using awk

Hi all, I need to sum values for fields in a delimited file as below: 2010-03-05||| 2010-03-05|||123 2010-03-05|467.621|369.532| 2010-03-06||| 2010-03-06||2| 2010-03-06|||444 2010-03-07||| 2010-03-07||| 2010-03-07|655.456|1019.301| Code used is: nawk -F "|" ' { sum +=... (7 Replies)
Discussion started by: Katabatic
7 Replies

5. Shell Programming and Scripting

loop + sum + print using awk

Hi, I am unable sum of each column in the loop usng awk command. Awk is not allowing the parameters in the command. i am facing the below error. awk: 0602-562 Field $() is not correct. Source file abc.txt 100,200,300,400,500,600,700,800,900 101,201,301,401,501,601,701,801,901 ... (1 Reply)
Discussion started by: number10
1 Replies

6. Shell Programming and Scripting

Loop through file to sum conditionally

Hi, I have a file with header, detail and trailer records. HDR|111 DTL|abc|100|xyz DTL|abc|50|xyz TRL|150 I need to add the values in 3rd field from DTL records. Using awk, I am doing it as follows: awk -F'|' '$1=="DTL"{a += $3} END {print a}' <source_file> However, I want to... (3 Replies)
Discussion started by: delta21
3 Replies

7. Shell Programming and Scripting

For Loop & SUM

pcmpath query device |awk 'BEGIN{print "DEVICE NAME\tSERIAL"} /DEVICE NAME/ {printf "%s\t", $5; getline; print substr($2, length($2)-3)}' This script returns output like below to pull out "DEVICE NAME SERIAL". ...... hdisk28 110B hdisk29 1112 hdisk30 1115 hdisk31 1116 hdisk32 1128... (2 Replies)
Discussion started by: Daniel Gate
2 Replies

8. Shell Programming and Scripting

Sum up numbers in a for loop

Hi i have to calculate some numbers, column by column. Herfore i used a for-loop.. for i in {4..26};do awk -F"," '{x'$i'+=$'$i'}END{print '$i'"\t" x'$i'}' file.tmp;done ----- printout ----- 4 660905240 5 71205272 6 8.26169e+07 7 8.85961e+07 8 8.60936e+07 9 7.42238e+07 10 5.6051e+07... (7 Replies)
Discussion started by: IMPe
7 Replies

9. Shell Programming and Scripting

Need help the sum from loop

Hi all, I have one host i need to run in loop to check the capacity from different frame and get the output to one file and sum it and convert to TB this is Code #!/bin/ksh DATE=`date '+%d%m%y'` for f in `cat /home/esx-capacity/esx-host.txt` do for g in `cat /home/esx-capacity/frame`... (10 Replies)
Discussion started by: ranjancom2000
10 Replies
Authen::CAS::Client(3pm)				User Contributed Perl Documentation				  Authen::CAS::Client(3pm)

NAME
Authen::CAS::Client - Provides an easy-to-use interface for authentication using JA-SIG's Central Authentication Service SYNOPSIS
use Authen::CAS::Client; my $cas = Authen::CAS::Client->new( 'https://example.com/cas' ); # generate an HTTP redirect to the CAS login URL my $r = HTTP::Response->new( 302 ); $r->header( Location => $cas->login_url ); # generate an HTTP redirect to the CAS logout URL my $r = HTTP::Response->new( 302 ); $r->header( Location => $cas->logout_url ); # validate a service ticket (CAS v1.0) my $r = $cas->validate( $service, $ticket ); if( $r->is_success ) { print "User authenticated as: ", $r->user, " "; } # validate a service ticket (CAS v2.0) my $r = $cas->service_validate( $service, $ticket ); if( $r->is_success ) { print "User authenticated as: ", $r->user, " "; } # validate a service/proxy ticket (CAS v2.0) my $r = $cas->proxy_validate( $service, $ticket ); if( $r->is_success ) { print "User authenticated as: ", $r->user, " "; print "Proxied through: "; print " $_ " for $r->proxies; } # validate a service ticket and request a proxy ticket (CAS v2.0) my $r = $cas->service_validate( $server, $ticket, pgtUrl => $url ); if( $r->is_success ) { print "User authenticated as: ", $r->user, " "; unless( defined $r->iou ) { print "Service validation for proxying failed "; } else { print "Proxy granting ticket IOU: ", $r->iou, " "; ... # map IOU to proxy granting ticket via request to pgtUrl ... $r = $cas->proxy( $pgt, $target_service ); if( $r->is_success ) { print "Proxy ticket issued: ", $r->proxy_ticket, " "; } } } DESCRIPTION
The "Authen::CAS::Client" module provides a simple interface for authenticating users using JA-SIG's CAS protocol. Both CAS v1.0 and v2.0 are supported. METHODS
new $url [, %args] "new()" creates an instance of an "Authen::CAS::Client" object. $url refers to the CAS server's base URL. %args may contain the following optional parameter: o fatal => $boolean If this argument is true, the CAS client will "die()" when an error occurs and $@ will contain the error message. Otherwise an "Authen::CAS::Client::Response::Error" object will be returned. See Authen::CAS::Client::Response for more detail on response objects. login_url $service [, %args] "login_url()" returns the CAS server's login URL which can be used to redirect users to start the authentication process. $service is the service identifier that will be used during validation requests. %args may contain the following optional parameters: o renew => $boolean This causes the CAS server to force a user to re-authenticate even if an SSO session is already present for that user. o gateway => $boolean This causes the CAS server to only rely on SSO sessions for authentication. If an SSO session is not available for the current user, validation will result in a failure. logout_url [%args] "logout_url()" returns the CAS server's logout URL which can be used to redirect users to end authenticated sessions. %args may contain the following optional parameter: o url => $url If present, the CAS server will present the user with a link to the given URL once the user has logged out. validate $service, $ticket [, %args] "validate()" attempts to validate a service ticket using the CAS v1.0 protocol. $service is the service identifier that was passed to the CAS server during the login process. $ticket is the service ticket that was received after a successful authentication attempt. Returns an appropriate Authen::CAS::Response object. %args may contain the following optional parameter: o renew => $boolean This will cause the CAS server to respond with a failure if authentication validation was done via a CAS SSO session. service_validate $service, $ticket [, %args] "service_validate()" attempts to validate a service ticket using the CAS v2.0 protocol. This is similar to "validate()", but allows for greater flexibility when there is a need for proxying authentication to back-end services. The $service and $ticket parameters are the same as above. Returns an appropriate Authen::CAS::Response object. %args may contain the following optional parameters: o renew => $boolean This will cause the CAS server to respond with a failure if authentication validation was done via a CAS SSO session. o pgtUrl => $url This tells the CAS server that a proxy ticket needs to be issued for proxying authentication to a back-end service. $url corresponds to a callback URL that the CAS server will use to verify the service's identity. Per the CAS specification, this URL must be HTTPS. If this verification fails, normal validation will occur, but a proxy granting ticket IOU will not be issued. Also note that this call will block until the CAS server completes its service verification attempt. The returned proxy granting ticket IOU can then be used to retrieve the proxy granting ticket that was passed as a parameter to the given URL. proxy_validate $service, $ticket [, %args] "proxy_validate()" is almost identical in operation to "service_validate()" except that both service tickets and proxy tickets can be used for validation and a list of proxies will be provided if proxied authentication has been used. The $service and $ticket parameters are the same as above. Returns an appropriate Authen::CAS::Response object. %args may contain the following optional parameters: o renew => $boolean This is the same as described above. o pgtUrl => $url This is the same as described above. proxy $pgt, $target "proxy()" is used to retrieve a proxy ticket that can be passed to a back-end service for proxied authentication. $pgt is the proxy granting ticket that was passed as a parameter to the "pgtUrl" specified in either "service_validate()" or "proxy_validate()". $target is the service identifier for the back-end system that will be using the returned proxy ticket for validation. Returns an appropriate Authen::CAS::Response object. BUGS
None are known at this time, but if you find one, please feel free to submit a report to the author. AUTHOR
jason hord <pravus@cpan.org> SEE ALSO
Authen::CAS::Client::Response More information about CAS can be found at JA-SIG's CAS homepage: <http://www.ja-sig.org/products/cas/> COPYRIGHT
Copyright (c) 2007-2009, jason hord All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: o Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. o Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. perl v5.10.0 2009-07-27 Authen::CAS::Client(3pm)
All times are GMT -4. The time now is 09:10 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy