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 302939913 by Zooma on Monday 30th of March 2015 10:06:02 PM
Old 03-30-2015
Hi,
Have created some code now that I think would do the trick if I didn't get syntax errors. Really appreciate any help.

Cheers!
/Z


Code:
#!/bin/ksh
sort -k1,1 -k3,3n -k2,2 stats.txt | awk 
BEGIN {	printf("%17s %7d %d %d %d %d\n",
		"destIP", "avgRetransTime", "maxRetransTime", "noRetrans", "noSuccPack", "transBytes")
	printf("---------- --------------- ---------------- -------------- -------------- ---------------\n")

}

# If the IP address found is not in the list
$1 != lIP {
	maxOverallTime = 0
	tempIp = $1
	noSuccPackPerIp=0
	transBytesPerIp=0
	
	while (tempIp == $1){
			transBytesPerIp=0
					
		$3 != lSeqNo{
			minTime = maxTime = $2
			cnt = 0
			
			# check this
			transBytesForSeqNo = $4
		
			while($3 == lSeqNo) {
				maxTime = $2
				cnt++
				next
			}
			
			if ((maxTime-minTime)>maxOverallTime){
				maxOverallTime=(maxTime-minTime)
			}
			
			if (count<10){
				noSuccPackPerIp++
				transBytesForSeqNo=0
			}
			transBytesPerIp += transBytesForSeqNo
			lSeqNo = $3
		}
	}
	printf("%17s %7d %11.3d %d %d %15d\n", lIP, (maxTime-minTime)/cnt, maxOverallTime, cnt, noSuccPackPerIp, transBytesForSeqNo)
}'

 

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
SbTime(3)							       Coin								 SbTime(3)

NAME
SbTime - The SbTime class instances represents time values. SbTime is a convenient way of doing system independent representation and calculations on time values of high resolution. SYNOPSIS
#include <Inventor/SbTime.h> Public Member Functions SbTime (void) SbTime (const double sec) SbTime (const int32_t sec, const long usec) SbTime (const struct timeval *const tv) void setToTimeOfDay (void) void setValue (const double sec) void setValue (const int32_t sec, const long usec) void setValue (const struct timeval *const tv) void setMsecValue (const unsigned long msec) double getValue (void) const void getValue (time_t &sec, long &usec) const void getValue (struct timeval *tv) const unsigned long getMsecValue (void) const SbString format (const char *const fmt='%S.%i') const SbString formatDate (const char *const fmt=NULL) const SbBool parsedate (const char *const date) SbTime & operator+= (const SbTime &tm) SbTime & operator-= (const SbTime &tm) SbTime operator- (void) const SbTime & operator*= (const double s) SbTime & operator/= (const double s) double operator/ (const SbTime &tm) const SbTime operator% (const SbTime &tm) const int operator== (const SbTime &tm) const int operator!= (const SbTime &tm) const SbBool operator< (const SbTime &tm) const SbBool operator> (const SbTime &tm) const SbBool operator<= (const SbTime &tm) const SbBool operator>= (const SbTime &tm) const void print (FILE *fp) const Static Public Member Functions static SbTime getTimeOfDay (void) static SbTime zero (void) static SbTime max (void) static SbTime maxTime (void) static void sleep (int msec) Friends SbTime operator+ (const SbTime &t0, const SbTime &t1) SbTime operator- (const SbTime &t0, const SbTime &t1) SbTime operator* (const double s, const SbTime &tm) SbTime operator* (const SbTime &tm, const double s) SbTime operator/ (const SbTime &tm, const double s) Detailed Description The SbTime class instances represents time values. SbTime is a convenient way of doing system independent representation and calculations on time values of high resolution. Constructor &; Destructor Documentation SbTime::SbTime (void) The default constructor sets up a time instance of 0 seconds. SbTime::SbTime (const doublesec) Construct and initialize an SbTime instance to a time specified as sec seconds. SbTime::SbTime (const int32_tsec, const longusec) Construct and initialize an SbTime instance to a date and time sec number of seconds and usec number of microseconds. SbTime::SbTime (const struct timeval *consttv) Construct and initialize an SbTime instance to the date and time given by the struct timeval. For information on the timeval structure, please consult your system developer documentation. Member Function Documentation SbTime SbTime::getTimeOfDay (void) [static] Returns an SbTime instance with the current clock time. The current time will be given as a particular number of seconds and microseconds since 00:00:00 January 1, 1970, in Coordinated Universal Time (UTC). See also: setToTimeOfDay(). void SbTime::setToTimeOfDay (void) Set this SbTime to be the current clock time. The current time will be given as a particular number of seconds and microseconds since 00:00:00.00 1st January 1970. See also: getTimeOfDay(). SbTime SbTime::zero (void) [static] Returns an SbTime instance representing zero time. See also: zero(). SbTime SbTime::max (void) [static] Returns an SbTime instance representing the maximum representable time/date. This method is not available under MSWindows, as max() crashes with a define macro Microsoft has polluted the global namespace with. See also: zero(). SbTime SbTime::maxTime (void) [static] Returns an SbTime instance representing the maximum representable time/date. See also: zero(). void SbTime::sleep (intmsec) [static] Suspends the current thread for msec milliseconds. See also: cc_sleep(). Since: Coin 3.0 void SbTime::setValue (const doublesec) Reset an SbTime instance to sec number of seconds. See also: getValue(). void SbTime::setValue (const int32_tsec, const longusec) Reset an SbTime instance to sec number of seconds and usec number of microseconds. See also: getValue(). void SbTime::setValue (const struct timeval *consttv) Reset an SbTime instance to the date and time given by the timeval struct. For information on the timeval struct, please consult your developer system documentation. See also: getValue(). void SbTime::setMsecValue (const unsigned longmsec) Set the time by msec number of milliseconds. See also: getMsecValue(). double SbTime::getValue (void) const Return time as number of seconds. See also: setValue(). void SbTime::getValue (time_t &sec, long &usec) const Return number of seconds and microseconds which the SbTime instance represents. See also: setValue(). void SbTime::getValue (struct timeval *tv) const Returns the time as a timeval structure. For information on the timeval structure, please consult your system developer documentation. See also: setValue(). unsigned long SbTime::getMsecValue (void) const Return number of milliseconds which the SbTime instance represents. Important note: you should in general avoid using this function, as it has an inherent API design flaw (from the original SGI Open Inventor design). The problem is that an unsigned long wraps around in a fairly short time when used for counting milliseconds: in less than 50 days. (And since SbTime instances are often initialized to be the time since the start of the epoch (ie 1970-01-01 00:00), the value will have wrapped around many, many times.) You are probably better off using the getValue() method which returns a double for the number of seconds, then multiply by 1000.0 if you need to know the current number of milliseconds of the SbTime instance. See also: setMsecValue() SbString SbTime::format (const char *constfmt = '%S.%i') const Uses the formatting specified below to return a string representation of the stored date/time. Any format specifiers must be prefixed with a '' symbol, any other text in the format string fmt will be copied directly to the resultant SbString. %% - insert a single ''. D - number of days. H - number of hours. h - remaining hours after subtracting number of days. M - number of minutes. m - remaining minutes after subtracting the total number of hours. S - number of seconds. s - remaining seconds after subtracting the total number of minutes. I - number of milliseconds. i - remaining milliseconds after subtracting the total number of seconds. U - number of microseconds. u - remaining microseconds after subtracting the total number of mseconds. The result shows UTC time, not corrected for local time zone nor daylight savings time. See also: formatDate(). SbString SbTime::formatDate (const char *constfmt = NULL) const Accepts the formatting identifiers specified by the POSIX strftime() function to return a string representation of the stored date. Check your reference documentation for strftime() for information on the format modifiers available. Default formatting is used if fmt is NULL. Note that the default formatting is different on Microsoft Windows systems versus all other systems. For Windows, it is '%#c', for other systems it is '%A, %D %r' (again, see system documentation on strftime() for more information). The value of SbTime will be interpreted as seconds since 00:00:00 1970-01-01. The result shows local time, according to local time zone and daylight savings time (if and when applicable). See also: format(). SbBool SbTime::parsedate (const char *constdate) This method takes a date string and converts it to the internal SbTime format. The date string must conform to one of three formats, namely the RFC 822 / RFC 1123 format (Wkd, DD Mnth YYYY HH:MM:SS GMT), the RFC 850 / RFC 1036 format (Weekday, DD-Mnth-YY HH:MM:SS GMT), or the asctime() format (Wkdy Mnth D HH:MM:SS YYYY). Feeding an invalid date string to this method will make it return FALSE. SbTime & SbTime::operator+= (const SbTime &tm) Add tm to time value and return reference to self. SbTime & SbTime::operator-= (const SbTime &tm) Subtract tm from time value and return reference to self. SbTime SbTime::operator- (void) const Return the negated time. SbTime & operator*= (const doubles) Multiply time value with s and return reference to self. SbTime & operator/= (const doubles) Divide time value with s and return reference to self. double operator/ (const SbTime &tm) const Find the factor between this SbTime and the one given in tm, and return the result. SbTime SbTime::operator% (const SbTime &tm) const Returns the remainder time when dividing on tm. int SbTime::operator== (const SbTime &tm) const Check if the time value is equal to that of tm. int SbTime::operator!= (const SbTime &tm) const Check if the time value is not equal to that of tm. SbBool SbTime::operator< (const SbTime &tm) const Compares with tm and return TRUE if less. SbBool SbTime::operator> (const SbTime &tm) const Compares with tm and return TRUE if larger than. SbBool SbTime::operator<= (const SbTime &tm) const Compares with tm and return TRUE if less or equal. SbBool SbTime::operator>= (const SbTime &tm) const Compares with tm and return TRUE if larger or equal. void SbTime::print (FILE *fp) const Dump the state of this object to the file stream. Only works in debug version of library, method does nothing in an optimized compile. Friends And Related Function Documentation SbTime operator+ (const SbTime &t0, const SbTime &t1) [friend] Add the two SbTimes and return the result. SbTime operator- (const SbTime &t0, const SbTime &t1) [friend] Subtract t1 from t0 and return the result. SbTime operator* (const doubles, const SbTime &tm) [friend] Multiply time value tm with s and return result. SbTime operator* (const SbTime &tm, const doubles) [friend] Multiply time value tm with s and return result. SbTime operator/ (const SbTime &tm, const doubles) [friend] Divide time value tm with s and return result. Author Generated automatically by Doxygen for Coin from the source code. Version 3.1.3 Wed May 23 2012 SbTime(3)
All times are GMT -4. The time now is 05:41 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy