Display consumer/service line with smallest time value
Display consumer/service line with smallest time value
(OP)
Hello All,
I have a file with three fields delimited by a comma:
field1 is a consumer name
field2 is the service used by a given consumer
filed3 is a time value
I would like to display the line for each consumer/service pair with the earlier time i.e. smallest time value
Sample input file:
Desired output:
Any assistance would be greatly appreciated. Thanks in advance.
I have a file with three fields delimited by a comma:
field1 is a consumer name
field2 is the service used by a given consumer
filed3 is a time value
I would like to display the line for each consumer/service pair with the earlier time i.e. smallest time value
Sample input file:
CODE
$ cat data arx-count-consumer,arx-count-service,300 arx-count-consumer,arx-count-service,500 peg-if-consumer,peg-if-service,1100 tin-mock-consumer,tin-mock-service,1500 arx-count-consumer,arx-count-service,101 tin-mock-consumer,tin-mock-service,4500 pipe-mock-consumer,pipe-mock-service,50 pipe1-mock-consumer,pipe-mock-service,510
Desired output:
CODE
arx-count-consumer,arx-count-service,101 peg-if-consumer,peg-if-service,1100 tin-mock-consumer,tin-mock-service,500 pipe-mock-consumer,pipe-mock-service,50 pipe1-mock-consumer,pipe-mock-service,510
Any assistance would be greatly appreciated. Thanks in advance.
RE: Display consumer/service line with smallest time value
Then for every line from your file, you could do:
- if array element min_time_values[key] does not exist yet, then create it by setting min_time_values[key] = time_value
- if array element min_time_values[key] already exist and when time_value is less than min_time_values[key] then change it by setting min_time_values[key] = time_value
RE: Display consumer/service line with smallest time value
tin-mock-consumer,tin-mock-service,500
but
tin-mock-consumer,tin-mock-service,1500
RE: Display consumer/service line with smallest time value
RE: Display consumer/service line with smallest time value
CODE
CODE
RE: Display consumer/service line with smallest time value
Maybe a small improvement: at the end you can use the split() function to restore the original values of consumer name and service:
CODE
CODE
RE: Display consumer/service line with smallest time value
RE: Display consumer/service line with smallest time value
CODE
Any advice would be greatly appreciated.
RE: Display consumer/service line with smallest time value
RE: Display consumer/service line with smallest time value
I have the correct result however I have done so via accidentally introducing a typo. Is someone able to explain why the below line works:
CODE
Is there is a better method for my required purpose?
CODE
CODE
CODE
RE: Display consumer/service line with smallest time value
CODE
RE: Display consumer/service line with smallest time value
CODE
Output:
CODE
RE: Display consumer/service line with smallest time value
Your solution is a clean and simpler approach to the problem posed.
A big thank you once again - excellent coding.