Sponsored Content
Top Forums Shell Programming and Scripting Filter on one column and then perform conditional calculations on another column with a Linux script Post 302939571 by Zooma on Thursday 26th of March 2015 03:32:36 PM
Old 03-26-2015
Thanks guys. Appreciate a lot. You've got some good questions Don and I realize I was fuzzy with the output and the description. So for the record I will describe a bit better here. The desired output would look like this:

Code:
destIP    avgRetransTime   maxRetransTime  noRetrans  noSuccPack  transBytes
-------- ----------------  --------------  ---------  ----------  ----------
1.2.3.4         0.335          0:47            3          2          1300
1.2.3.5         0.05           0:05            1          2          1580

So only one resulting line per destination IP with the following info:
1. IP address.

2. avgRetransTime: derived by finding the time difference between the first and last packet with same IP and sequence number and then divide that with number of seq numbers that are subject to retransmission. Example: For 1.2.3.4, there have been two seq numbers with retransmissions. For 123, the time between the last and first packet is 0:47 seconds (0:48-0:01). For 124 it's 0.2 seconds (0:72-0:52). So the average time is (0:47+0:2)/2=0.335.

3. maxRetransTime: The sequence number that took longest time to retransmit. For 1.2.3.4 it's 123 which took 0:47 seconds.

4. noRetrans: All retransmissions counted. For 1.2.3.4, packet 123 has been sent 3 times (2 retransmissions) and packet 124 has been sent 2 times (1 retransmission). So a total of 3.

5. noSuccPack: The number of packets (per IP) that are considered delivered. For 1.2.3.4, both 123 and 124 are considered delivered unless the number of retransmissions for a single sequence number exceeds 5. Then the packet is considered "not delivered".

6. transBytes: Each time a packet delivery is successful (counted as the last time the sequence number is seen if the sequence number is not repeated more than 5 times), this parameter is incremented with the number of Bytes.

Your code is very straight forward and useful. I think I will be able to adjust it to get what I need. Almost :-). What's missing is this:

The "loop" is repeated as long as the IP address and the seq No are the same. Given my desired output I want to sum up a few things, make some divisions and so on. Feels like I need a loop that knows if it's the last lap inside of the brackets so to say. "If this is the last time I see this combination of IP and seq No I should sum up things and divide etc.". That's why I tried to go for the do-while loop. Could you recommend how to approach this one?

Thanks!
/Z

Last edited by Zooma; 03-26-2015 at 04:36 PM.. Reason: Fixed code formatting.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to perform calculations using numbers greater than 2150000000.

Could someone tell me how to perform calculations using numbers greater than 2150000000 in Korn Shell? When I tried to do it it gave me the wrong answer. e.g. I have a ksh file with the contents below: --------------------------------- #!/bin/ksh SUM=`expr 2150000000 + 2` PRODUCT=`expr... (3 Replies)
Discussion started by: stevefox
3 Replies

2. Shell Programming and Scripting

Sed or awk script to remove text / or perform calculations from large CSV files

I have a large CSV files (e.g. 2 million records) and am hoping to do one of two things. I have been trying to use awk and sed but am a newbie and can't figure out how to get it to work. Any help you could offer would be greatly appreciated - I'm stuck trying to remove the colon and wildcards in... (6 Replies)
Discussion started by: metronomadic
6 Replies

3. Shell Programming and Scripting

Conditional aggregation and print of a column in file

Hi My input file looks like field1 field2 field3 field4 field5 field1 field2 field3 field4 field5 field1 field2 field3 field4 field5 :::::::::::: :::::::::::: There may be one space of multiple spaces between fields and no fields contains spaces in them. If field 1 to 4 are equal for... (3 Replies)
Discussion started by: bittoo
3 Replies

4. Shell Programming and Scripting

Replace a column with a value conditional on a value in col1

Hi, Perhaps a rather simple problem...? I have data that looks like this. BPC0013 ANNUL_49610 0 0 1 1 BPC0014 ANNUL_49642 0 0 2 1 BPC0015 ANNUL_49580 0 0 1 1 BPC0016 ANNUL_49596 0 0 2 1 BPC0017 VULGO_49612 0 0 1 1 BPC0018 ANNUL_49628 0 0 1 1 BPC0019 ANNUL_49692 0 0 2 1 170291_HMG... (4 Replies)
Discussion started by: genehunter
4 Replies

5. Shell Programming and Scripting

Enter third column & Perform Operation

I am trying to enter a third column in this file, but the third column should that I call "Math" perform a some math calculations based on the value found in column #2. Here is the input file: Here is the desired output: Output GERk0203078$ Levir Math Cotete_1... (5 Replies)
Discussion started by: Ernst
5 Replies

6. Shell Programming and Scripting

awk , conditional involving line and column

Dear All, I indeed your help for managing resarch data file. for example I have, data1.txt : type of atoms z vz Si 34 54 O 20 56 H 14 13 Si 40 17 O ... (11 Replies)
Discussion started by: ariesto
11 Replies

7. UNIX for Dummies Questions & Answers

Command line / script option to filter a data set by values of one column

Hi all! I have a data set in this tab separated format : Label, Value1, Value2 An instance is "data.txt" : 0 1 1 -1 2 3 0 2 2 I would like to parse this data set and generate two files, one that has only data with the label 0 and the other with label -1, so my outputs should be, for... (1 Reply)
Discussion started by: gnat01
1 Replies

8. Shell Programming and Scripting

awk script concatenate two column and perform mutiplication

Need your help in solving this puzzle. Any kind of help will be appreciated and link for any documents to read and learn and to deal with such scenarios would be helpful Concatenate column1 and column2 of file 1. Then check for the concatenated value in Column1 of File2. If found extract the... (14 Replies)
Discussion started by: as7951
14 Replies

9. Shell Programming and Scripting

awk script to append suffix to column when column has duplicated values

Please help me to get required output for both scenario 1 and scenario 2 and need separate code for both scenario 1 and scenario 2 Scenario 1 i need to do below changes only when column1 is CR and column3 has duplicates rows/values. This inputfile can contain 100 of this duplicated rows of... (1 Reply)
Discussion started by: as7951
1 Replies

10. Shell Programming and Scripting

Conditional Column Value

Hi Folks, I'm trying tog ain further experience with shell programming and have set my a small goal of writing a little filesystem monitoring script. So far my output is as follows: PACMYDB03 Filesystem Size Used Avail Use% Status /usr/local/mysql/data ... (5 Replies)
Discussion started by: Axleuk
5 Replies
Net::SIP::Dispatcher(3pm)				User Contributed Perl Documentation				 Net::SIP::Dispatcher(3pm)

NAME
Net::SIP::Dispatcher - dispatch SIP packets between legs and endpoint SYNOPSIS
my $disp = Net::SIP::Dispatcher->new( ... ); $disp->deliver( $request ); DESCRIPTION
This module dispatches Net::SIP::Packets between Net::SIP::Legs and endpoints like Net::SIP::Endpoint, Net::SIP::Registrar and Net::SIP::StatelessProxy. It manages retransmission of outgoing packets and redelivery of responses to incoming requests. It is asssociated with an event handling like Net::SIP::Dispatcher::Eventloop. CONSTRUCTOR
new ( @LEGS, EVENTLOOP, %ARGS ) Creates a new dispatcher object. @LEGS is a list of legs or specification for legs. See add_leg for possible formats. EVENTLOOP is a eventloop which provides handling of events on file descriptors and timers. If not given a new Net::SIP::Dispatcher::Eventloop object will be created and used. See there how to define your own event loop package. %ARGS are parameters for the behavior of the dispatcher: outgoing_proxy Specifies "ip:port" of outgoing proxy, e.g the proxy which will be used for all outgoing packets. If no leg but an outgoing proxy is specified a leg will be created which can reach the outgoing proxy by udp. do_retransmits If TRUE retransmits will be done accoring to RFC3261. If FALSE no retransmits will be done, which is used in the case of stateless proxies. Defaults to TRUE. This is the default for the delivery and can be overwritten in sub deliver. domain2proxy Optional mapping between target SIP domain and proxy to use. This is usually a hash of "( domain, "ip_proxy:port_proxy" )" pairs. Special domain '*' can be used to specify a fallback and '*.domain' to include not only the domain but the subdomains too. See sub deliver for more details. The constructor will create a timer using the eventloop which will regularly (each second) call queue_expire. METHODS
set_receiver ( ENDPOINT ) This sets ENDPOINT as a receiver for incoming packets. ENDPOINT is an object with a method receive or a callback usable by invoke_callback in Net::SIP::Util. add_leg ( LEG ) Adds LEG as a leg to the dispatcher $self. LEG can be either a Net::SIP::Leg object, a IO::Handle or a hash reference which is usable in the constructor of Net::SIP::Leg. The leg will be added to the dispatchers eventloop for receiving incoming packets. remove_leg ( LEG ) Removes Net::SIP::Leg object LEG from the dispatcher. get_legs ( %ARGS ) Get a list of all Net::SIP::Leg objects matching the criteria given by %ARGS. %ARGS can be a combination of: addr Matches if given address matches the legs source address. port Matches if given port matches the legs source port. proto Matches if given proto ('udp','tcp') matches the legs protocol. sock Matches if the given IO::Handle is used as the socket in the leg. sub Call given sub with the Net::SIP::Leg as argument. Matches if the sub returns TRUE. The leg matches %ARGS if the all conditions specified in %ARGS match. add_timer ( WHEN, CALLBACK, [ REPEAT ] ) Adds a timer using the eventloop. WHEN is either an absolute or a relative time (what it is will be decided based on the value of WHEN). Absolute times will be specified in time_t (seconds since 1970-01-01 00:00:00) and relative time will be specified in seconds. WHEN can be floating point to specifiy subseconds. WHEN can be 0 to trigger the timer immediatly. CALLBACK is a callback usable by invoke_callback in Net::SIP::Util. REPEAT is the optional repeat interval for the timer. deliver ( PACKET, %ARGS ) Delivers Net::SIP::Packet PACKET. %ARGS can speciffy hints for delivery: id ID for packet, used in cancel_delivery. If not given the transaction ID of PACKET given by method tid will be used. callid Call-ID for packet, used in cancel_delivery to cancel all deliveries for a specific call. If not given the Call-Id of PACKET given by method callid will be used. callback callback which will be called on definite delivery of packet (only possible for TCP) or on definite failure. Callback will be invoked using invoke_callback from Net::SIP::Util with the additional argument of $!. See sub deliver in Net::SIP::Leg. leg Specifies outgoing Net::SIP::Leg object. For responses created by the endpoint the outgoing leg is usually known, because it's the same as the incoming leg for the request. dst_addr "ip:port" where to deliver the packet. This is necessary for responses, for requests it can be find out based on the requests URI. do_retransmits Specifies if retransmits should be done according to RFC3261. This is usually the case, except for stateless proxies. Overwrites the global parameter with the same name from the constructor for the delivery of the specific packet. Delivery of the packet itself will be handled in multiple steps (in the code done mainly by sub __deliver: o If a leg is specified it will be used for delivery. dst_addr needs to be specified in this case too. This is usually the case for locally generated responses. o Otherwise leg and dst_addr will be retrieved using resolve_uri. See there. If the packets could be retransmitted appropriate setups will be done. Retransmission will be done until final failure or until cancel_delivery will be called for the packet, which usually means, that the packet was successfully delivered because a response to the packet was received. resolve_uri ( URI, ADDR, LEGS, CALLBACK, [ ALLOWED_PROTO, ALLOWED_LEGS ] ) Resolves URI to get the destination address and the outgoing leg. ADDR and LEGS are references to lists which will get filled with the computed values. If ALLOWED_PROTO is given it will be interpreted as a @list of protocols. Only the protocols given in the list will be considered and the it will try them in the order from the list, e.g. "('tcp','udp')" means that tcp is tried first and only if there is no way to do tcp it will try udp. Default is to first try udp and then tcp. If ALLOWED_LEGS is given it will be interpreted as a @list of Net::SIP::Leg objects and only these legs are allowed. Because the method can be asynchronous (DNS lookups can be involved) it will call CALLBACK once it is done. If no errors occured CALLBACK will be invoked without additional arguments, otherwise with the errno as additional argument. Resolving will be done as follows: o If domain2proxy is given it will try to get the dst_addr from this, e.g. the address of the proxy responsable for the domain (if any). From dst_addr it will then get the leg. o If still no dst_addr is known it will use outgoing_proxy as the dst_addr. o If still no dst_addr is known but the SIP domain is an IP address this will be used as dst_addr. o The last effort will be made by looking up the SIP domain using DNS with a partial implementation of RFC3263, e.g. it looks at the DNS SRV records but not at NAPTR records. o For each destination address (e.g. proto,addr,port) the outgoing leg will be computed. This will be done in sub __find_leg4addr by going through all legs and checking, if the leg could deliver to this address by calling can_deliver_to on the leg (see Net::SIP::Leg). cancel_delivery ( TYP?,ID ) Cancels retransmission of packet with id ID. Called from endpoint if response to packet came in, which means that the packet was successfully delivered. If TYP given packets can be canceled by something else. TYP can be "callid", in which case all deliveries for a specific call will be canceled. It can be "id" which will cancel the packet with id ID. Or it can be "qentry" in which case ID will be interpreted as the Net::SIP::Dispatcher::Packet object in the queue and it will cancel this packet. Will return true if the item was canceled, false if no such item was found in delivery queue. receive ( PACKET, LEG, FROM ) Called from the eventloop (e.g was setup as a callback) for incoming packets. The new Net::SIP::Packet is PACKET, LEG is the Net::SIP::Leg where the packet came in and FROM is "ip:port" of the sender. queue_expire ( [ NOW ] ) Expires retransmission queue, e.g. deletes packet where retransmissions failed permanently (and calls appropriate callbacks) and initiates pending retransmissions. Called from a timer setup in the constructor. perl v5.14.2 2010-07-12 Net::SIP::Dispatcher(3pm)
All times are GMT -4. The time now is 08:33 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy