Sponsored Content
Top Forums Shell Programming and Scripting Count occurrence of column one unique value having unique second column value Post 302978669 by RudiC on Tuesday 2nd of August 2016 11:27:04 AM
Old 08-02-2016
If the index constructed from $1 and $2 does not exist in the temp array T, its a new combination, and the counter for $1 is incremented. When the input file ends, all these counters and the corresponding $1 values are printed.

More detailed:
For the first occurrence of the $1,$2 combination, T[$1,$2] doesn't exist, so !T[$1,$2] is true, and the counter C[$1] is incremented. Due to the increment of T , the next time the combination is encountered, nothing will happen. C[$1] thus counts up the different $2s for every single $1. In the end, the count for every single $1 is printed.

Last edited by RudiC; 08-02-2016 at 03:41 PM..
This User Gave Thanks to RudiC For This Post:
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

print unique values of a column and sum up the corresponding values in next column

Hi All, I have a file which is having 3 columns as (string string integer) a b 1 x y 2 p k 5 y y 4 ..... ..... Question: I want get the unique value of column 2 in a sorted way(on column 2) and the sum of the 3rd column of the corresponding rows. e.g the above file should return the... (6 Replies)
Discussion started by: amigarus
6 Replies

2. Shell Programming and Scripting

awk pattern match and count unique in column

Hi all I have a need of searching some pattern in file by month and then count unique records D11 G11 R11 -------> Pattern available in file S11 Jan$1 to $5 column contains some records in which I want to find unique for this purpose I have written script like below awk '/Jan/ ||... (4 Replies)
Discussion started by: nex_asp
4 Replies

3. Shell Programming and Scripting

Count frequency of unique values in specific column

Hi, I have tab-deliminated data similar to the following: dot is-big 2 dot is-round 3 dot is-gray 4 cat is-big 3 hot in-summer 5 I want to count the frequency of each individual "unique" value in the 1st column. Thus, the desired output would be as follows: dot 3 cat 1 hot 1 is... (5 Replies)
Discussion started by: owwow14
5 Replies

4. UNIX for Dummies Questions & Answers

Grep unique 1st column

Hello, I'm trying to used awk but am new to this. I have a file like this: Bob is a good boy Bob is a strange person Bob is a good dancer Jane can party Jane is a good girl Jane is batty I'd like to get this: Bob is a good boy is a strange person is a good dancer Jane... (4 Replies)
Discussion started by: Billyjo
4 Replies

5. Shell Programming and Scripting

Sorting unique by column

I am trying to sort, do uniq by 1st column and report this 4 columns tab delimiter table , eg chr10:112174128 rs2255141 2E-10 Cholesterol, total chr10:112174128 rs2255141 7E-16 LDL chr10:17218291 rs10904908 3E-11 HDL Cholesterol chr10:17218291 rs970548 8E-9 TG... (4 Replies)
Discussion started by: fat
4 Replies

6. UNIX for Dummies Questions & Answers

Removing rows that contain non-unique column entry

Background: I have a file of thousands of potential SSR primers from Batch Primer 3. I can't use primers that will contain the same sequence ID or sequence as another primer. I have some basic shell scripting skills, but not enough to handle this. What you need to know: I need to remove the... (1 Reply)
Discussion started by: msatseqs
1 Replies

7. UNIX for Beginners Questions & Answers

Find unique values but only in column 1

Hi All, Does anyone have any suggestions/examples of how i could show only lines where the first field is not duplicated. If the first field is listed more than once it shouldnt be shown even if the other columns make it unique. Example file : 876,RIBDA,EC2 876,RIBDH,EX7 877,RIBDF,E28... (4 Replies)
Discussion started by: mutley2202
4 Replies

8. UNIX for Beginners Questions & Answers

Count unique column

Hello, I am trying to count unique rows in my file based on 4 columns (2-5) and to output its frequency in a sixth column. My file is tab delimited My input file looks like this: Colum1 Colum2 Colum3 Colum4 Coulmn5 1.1 100 100 a b 1.1 100 100 a c 1.2 200 205 a d 1.3 300 301 a y 1.3 300... (6 Replies)
Discussion started by: nans
6 Replies

9. Shell Programming and Scripting

Count number of unique values in each column of array

What is an efficient way of counting the number of unique values in a 400 column by 1000 row array and outputting the counts per column, assuming the unique values in the array are: A, B, C, D In other words the output should look like: Value COL1 COL2 COL3 A 50 51 52... (16 Replies)
Discussion started by: Geneanalyst
16 Replies
TAPSET::SNMP(3stap)													       TAPSET::SNMP(3stap)

NAME
tapset::snmp - Systemtap simple network management protocol probe points. DESCRIPTION
This family of probe points enhances the Linux system's implementation of the Simple Network Management Protocol (SNMP) by allowing the user to collect per-socket statistics. SNMP data is collected in the Linux kernel by counting various events occurring in the networking subsystem. Linux provides one counter for each type of event, thus providing a system-wide collection of network statistics. These statis- tics can be viewed with the command: netstat -s. The probe points defined in the SNMP group of tapsets allow users to aberrate each SNMP counter into groups of counters. For example, the user may count SNMP events for a single network socket or for a group of sockets. Severals SNMP tapsets have been created. Each tapset represents a single layer of the network stack and defines a group of counters called management information blocks or MIBs. Currently tapsets are provided that support MIBS for IP, TCP layers and the enhanced linux MIB. See the file /usr/include/linux/snmp.h for a list of MIBS supported by linux. PROBE HANDLERS, COUNTERS AND CALLBACKS Each probe represents a single SNMP statistic. The probe's handler is called each time the system performs an operation that would alter the associated statistic. Each probe also defines an indexed set of counters used to record probe hits. The probe handler calls a user sup- plied callback functions to determine which counter to alter. The user's callback should return a key value that will be used to index the counter. For example a callback could return a unique value for each socket. This would results in a separate counter being used for each socket. Each tapset is now described. Examples of probe names and counter names are given. See the tapset itself for a complete list of supported probes. Users of the tapset must provide a callback function matching the name and prototype as shown. IP MIB Tapset: Example probe name: ipmib.InReceives Example counter name: InReceives Callback prototype: ipmib_filter_key:long (skb:long, op:long, SourceIsLocal:long) This user supplied function should compute and return a value used to index the statistical counter. The skb is a pointer to the struct sk_buff being processed at the time. The local ip-address and port number will be located in either the source or destination fields of the network packet. SourceIsLocal will be true if the local address is in the source field. The probe handler will add the value of op to the counter. To skip counting the event return a value of zero. TCP MIB tapset: Example probe name: tcpmib.InSegs Example counter name: InSegs Callback prototype: tcpmib_filter_key:long (sk:long, op:long) This user supplied function should compute and return a value used to index the statistical counter. The sk is a pointer to the struct sock being processed at the time. The probe handler will add the value of op to the counter. To skip counting the event return a value of zero. LINUX MIB tapset: linuxmib.stp Example probe name: linuxmib.DelayedACKs Example counter name: DelayedACKs Callback prototype: linuxmib_filter_key:long (sk:long, op:long) This user supplied function should compute and return a value used to index the statistical counter. The sk is a pointer to the struct sock being processed at the time. The probe handler will add the value of op to the counter. To skip counting the event return a value of zero. EXAMPLE
This example script counts the number of TCP retransmits and records them per-remote address. It displays the counts when terminated. /* Enable the statistic we want to record. */ probe tcpmib.RetransSegs {} /* * Find the remote address and return * it as an index to the counter array. */ function tcpmib_filter_key: long ( sk:long, op:long ){ if ( !sk ) return 0; raddr = sk_get_daddr(sk); return raddr } /* Print the results. */ probe end { foreach (addr in RetransSegs ) printf ("%s %d ",ip_ntop(htonl(addr)), lport) } FILES
/usr/share/doc/systemtap*/examples/tcpipstat.stp SEE ALSO
stap(1), stapprobes(3stap), stapfuncs(3stap) IBM
TAPSET::SNMP(3stap)
All times are GMT -4. The time now is 08:29 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy