Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Create range of bins counting values and add the percentage Post 303044451 by jiam912 on Friday 21st of February 2020 02:15:24 PM
Old 02-21-2020
Create range of bins counting values and add the percentage

Objective, create a table of range of bins to count the values for each range in column 2.

The purpose is to count at beginning all values in column 2 which contends value =0 or < 0.01
Then create the range of binnes counting values in column 2 > 0.01

The range of bins need to be extended to the MAX value in my case 20, even if these values are not found in the column.

Input file
Code:
121 0.98
121 0.98
121 1.47
121 1.47
121 0.00
121 0.00
121 0.00
121 0.10
121    2
121    3
121    7
121    0
121    0
121   10
121   12
121   15

Desired output file

Code:
            0    5    31.3%
 0.01 -  2.00    6    37.5%
 2.01 -  4.00    1     6.3%
 4.01 -  6.00    0     0.0%
 6.01 -  8.00    1     6.3%
 8.01 - 10.00    0     0.0%
10.01 - 12.00    2    12.5%
12.01 - 14.00    0     0.0%
14.01 - 16.00    1     6.3%
16.01 - 18.00    0     0.0%
18.01 - 20.00    0     0.0%
      > 20       0     0.0%
----------------------------
      Total:    16


Code Use
This code works well, but dont count values with exactly 0, and dont force the range of bins to the maximun value.

Code:
awk -v"MIN=0" -v"MAX=20" '
BEGIN   {delta = (delta=="")?2:delta
         MXBCK = (MAX / delta) + 1
        }

        {bucketNr = int(($2+delta) / delta)
         if (bucketNr > MXBCK) bucketNr = MXBCK
         cnt[bucketNr] ++
         TOT           ++ $2
         numBuckets = (numBuckets > bucketNr ? numBuckets : bucketNr)
        }

END     {
for (bucketNr=1; bucketNr<numBuckets; bucketNr++)      {end = beg + delta
         printf " %05.2f - %05.2f %6d %6.2f%%\n", beg, end, cnt[bucketNr], cnt[bucketNr] / TOT *100
         beg = end
         }
         printf "       > %5.2f %6d %6.2f%%\n", MAX, cnt[MXBCK], cnt[MXBCK] / TOT *100
         print "----------------------------"
         print "        Total:", TOT
        }
' file

Thanks in advance

Last edited by jiam912; 02-22-2020 at 06:13 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to calculate the percentage for the values in column

Hi, I am having the file which contains the following two columns. 518 _factorial 256 _main 73 _atol 52 ___do_global_ctors 170 ___main 52 ___do_g How can calculate the percentage of each value in the first column ? first need to get the sum of the first column and... (3 Replies)
Discussion started by: saleru_raja
3 Replies

2. Shell Programming and Scripting

To Create range of values

Hi, I have a file with the below like values with integers only in sorted order (May or may not be in sequence) Eg: File1.txt ----------- 1 2 3 4 5 6 . . . . . 10000 My requirement here is to create a range of values out put to a temp k (4 Replies)
Discussion started by: shiva447
4 Replies

3. Shell Programming and Scripting

Howto: easy date range iteration/counting on GNU systems in the shell

Should work in any shell, but requires GNU date, although GNU date seems only to be happy for input dates between 1902 and 2037, inclusive (49673 days). Assume $a and $b hold two dates, e.g. set a=2010-03-27 set b=2010-04-04 Marginally faster: iterator: seq -f "$a +%1.0f days" 1 50000 |... (0 Replies)
Discussion started by: laddiebuck
0 Replies

4. UNIX for Dummies Questions & Answers

Working out the percentage between two values

Hi there, I am totally new to Unix, I am trying to work out the percentage between two values in a ksh shell script and assign the result to a variable. Value1=577 Values2=244 So the calculation would be as follows: ((Value1 - Value2) / Value1) * 100 How would I be able to achieve... (2 Replies)
Discussion started by: NextLevelAndi
2 Replies

5. Shell Programming and Scripting

return counting per hour percentage

We have a monitoring process for a load in unix box, during this process we are writing logs statements for each record, and during this process we are showing the counts per hour. Here is that how we are following log files statements: (just two lines printed here), these statements logged at... (1 Reply)
Discussion started by: skkuchipudi
1 Replies

6. Shell Programming and Scripting

Calculating frequency of values within bins

Hi, I am working with files containing 2 columns in which i need to come up with the frequency/count of values in col. 2 falling within specifics binned values of col. 1. the contents of a sample file is shown below: 15 12.5 15 11.2 16 0.2 16 1.4 17 1.6 18 4.5 17 5.6 12 8.6 11 7.2 9 ... (13 Replies)
Discussion started by: ida1215
13 Replies

7. Shell Programming and Scripting

Convert Column Values to a Range of Values

I have a list of columns with values that I need to transform into a row containing the range of each column. For example: "Column A" 1 2 3 4 10 12 14 15 16 17 18 "Column B" 1 4 5 6 (4 Replies)
Discussion started by: newbio
4 Replies

8. Shell Programming and Scripting

Delete row if both percentage values are equal to zero

Hello, I have compiled a script but I have stucked at one point. Each line contains two pcs of % value and what I want to do is to delete any line if both % values are zero. data: expected output: ow3 should be deleted as both percentage value in related line are equal to zero. ... (2 Replies)
Discussion started by: baris35
2 Replies

9. Shell Programming and Scripting

Create range of values and count values.

Gents, It is possible to generate a range of values according to column 1 and count the total of rows in the range. example input 15.3 15.5 15.8 15.9 16.0 16.1 16.8 17.0 17.5 18.0 output desired 15.0 - 15.9 = 4 (10 Replies)
Discussion started by: jiam912
10 Replies

10. UNIX for Beginners Questions & Answers

Create bins with totals and percentage

I would like to create bins to get histogram with totals and percentage, e.g. starting from 0. If possible to set the minimum and maximum value in the bins ( in my case value min=0 and max=20 ) Input file 8 5 10 1 11 4 12 4 12 4 13 5 16 7 18 9 16 9 17 7 18 5 19 5 20 1 21 7 (10 Replies)
Discussion started by: jiam912
10 Replies
SLAPO-RETCODE(5)						File Formats Manual						  SLAPO-RETCODE(5)

NAME
slapo-retcode - return code overlay to slapd SYNOPSIS
/etc/ldap/slapd.conf DESCRIPTION
The retcode overlay to slapd(8) is useful to test the behavior of clients when server-generated erroneous and/or unusual responses occur, e.g. error codes, referrals, excessive response times and so on. The error responses are generated according to different strategies. In the first case, all operations targeted at a specific configurable subtree cause the object related to the request DN to be looked up and checked for return code data: a response code, plus an optional textual message, an optional configurable delay, an optional matched DN field, and, when the response code is "referral", a (list of) referral(s). Well-known response codes from standard track documents are provided in retcode.conf, which can be included after instantiating the over- lay. In the second case, objects of classes inherited from the errAbsObject, like errObject or errAuxObject, when returned as intermediate responses of a search request, are changed into the response dictated by their content. A third mode causes objects to be looked up from the underlying database to discover if their class inherits from errABsObject; in that case, their content is used to compute the corresponding response. The behavior is disabled by using the manageDSAit control (RFC 3296); in that case, the resulting object, either present in the directory or dynamically generated by the overlay, or contained in the request, is handled as usual. The config directives that are specific to the retcode overlay must be prefixed by retcode-, to avoid conflicts with directives specific to the underlying database or to other stacked overlays. The following specific directives can be used to configure the retcode overlay: retcode-parent <DN> This directive defines the parent DN where dynamically generated entries reside. If not defined, the suffix of the database is used. retcode-item <RDN> <errCode> [op=<oplist>] [text=<message>] [ref=<referral>] [sleeptime=<sec>] [matched=<DN>] [unsolicited=<OID>[:<data>]] [flags=[{pre|post}-]disconnect[,...]] A dynamically generated entry, located below retcode-parent. The errCode is the number of the response code; it can be in any format supported by strtol(3). The optional oplist is a list of operations that cause response code generation; if absent, all operations are affected. The matched field is the matched DN that is returned along with the error, while the text field is an optional diagnostics message. The ref field is only allowed for the referral response code. The sleeptime field causes slapd(8) to sleep the specified number of seconds before proceeding with the operation. The unsolicited field can be used to cause the return of an RFC 4511 unsolicited response message; if OID is not "0", an extended response is generated, with the optional data appended. If flags contains disconnect, or pre-disconnect, slapd(8) disconnects abruptly, without notice; post-disconnect causes disconnection right after sending response as appropriate. retcode-indir Enables exploitation of in-directory stored errAbsObject. May result in a lot of unnecessary overhead. retcode-sleep [-]<n> Defines a sleep time in seconds that is spent before actually handling any operation. If negative, a random time between 0 and the absolute value of the argument is used. SCHEMA
The retcode overlay utilizes the "return code" schema described herein. This schema is specifically designed for use with this overlay and is not intended to be used otherwise. It is also noted that the schema described here is a work in progress, and hence subject to change without notice. The schema is loaded automatically by the overlay. The schema includes a number of object classes and associated attribute types as described below. The error code: ( 1.3.6.1.4.1.4203.666.11.4.1.1 NAME ( 'errCode' ) DESC 'LDAP error code' EQUALITY integerMatch ORDERING integerOrderingMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 SINGLE-VALUE ) The operations that trigger the response code: ( 1.3.6.1.4.1.4203.666.11.4.1.2 NAME ( 'errOp' ) DESC 'Operations the errObject applies to' EQUALITY caseIgnoreMatch SUBSTR caseIgnoreSubstringsMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 ) The text message: ( 1.3.6.1.4.1.4203.666.11.4.1.3 NAME ( 'errText' ) DESC 'LDAP error textual description' EQUALITY caseIgnoreMatch SUBSTR caseIgnoreSubstringsMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SINGLE-VALUE ) The sleep time before the response is actually returned to the client: ( 1.3.6.1.4.1.4203.666.11.4.1.4 NAME ( 'errSleepTime' ) DESC 'Time to wait before returning the error' EQUALITY integerMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 SINGLE-VALUE ) The matched DN returned to the client: ( 1.3.6.1.4.1.4203.666.11.4.1.5 NAME ( 'errMatchedDN' ) DESC 'Value to be returned as matched DN' EQUALITY distinguishedNameMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 SINGLE-VALUE ) The OID to be returned as extended response OID in RFC 4511 unsolicited responses ("0" generates a regular response with msgid set to 0): ( 1.3.6.1.4.1.4203.666.11.4.1.6 NAME ( 'errUnsolicitedOID' ) DESC 'OID to be returned within unsolicited response' EQUALITY objectIdentifierMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 SINGLE-VALUE ) The octet string to be returned as extended response data in RFC 4511 unsolicited response: ( 1.3.6.1.4.1.4203.666.11.4.1.7 NAME ( 'errUnsolicitedData' ) DESC 'Data to be returned within unsolicited response' SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 SINGLE-VALUE ) If TRUE, slapd(8) disconnects abruptly without notice; if FALSE, it disconnects after sending response as appropriate: ( 1.3.6.1.4.1.4203.666.11.4.1.8 NAME ( 'errDisconnect' ) DESC 'Disconnect without notice' SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 SINGLE-VALUE ) The abstract class that triggers the overlay: ( 1.3.6.1.4.1.4203.666.11.4.3.0 NAME ( 'errAbsObject' ) SUP top ABSTRACT MUST ( errCode ) MAY ( cn $ description $ errOp $ errText $ errSleepTime $ errMatchedDN ) ) The standalone structural objectclass for specifically created data: ( 1.3.6.1.4.1.4203.666.11.4.3.1 NAME ( 'errObject' ) SUP errAbsObject STRUCTURAL ) The auxiliary objectclass to alter the behavior of existing objects: ( 1.3.6.1.4.1.4203.666.11.4.3.2 NAME ( 'errAuxObject' ) SUP errAbsObject AUXILIARY ) EXAMPLE
overlay retcode retcode-parent "ou=RetCodes,dc=example,dc=com" # retcode.conf is found in tests/data/ of the source tree include ./retcode.conf # Wait 10 seconds, then return success (0x00) retcode-item "cn=Success after 10 seconds" 0x00 sleeptime=10 # Wait 10 seconds, then return timelimitExceeded (0x03) retcode-item "cn=Timelimit after 10 seconds" 0x03 sleeptime=10 FILES
/etc/ldap/slapd.conf default slapd configuration file SEE ALSO
slapd.conf(5), slapd-config(5), slapd(8). The slapo-retcode(5) overlay supports dynamic configuration via back-config. ACKNOWLEDGEMENTS
This module was written in 2005 by Pierangelo Masarati for SysNet s.n.c. OpenLDAP 2012/04/23 SLAPO-RETCODE(5)
All times are GMT -4. The time now is 08:49 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy