How to compare the strings using < (Greater than symbol)

awksed

Below is my input file:

PA43410-2,1,3,/vobs/atlas-idc/src/utils/logger/IDCLogger/IDC.cpp,48,19:16:46.523.177, 2 PS Sensor Value = -5.501000 , Min = -5.583000 , Max = -5.319000
PA43410-2,1,3,/vobs/atlas-idc/src/utils/logger/IDCLogger/IDC.cpp,48,19:16:46.523.210, 3 PS Sensor Value = 15.996000 , Min = 15.814000 , Max = 16.078000
PA43410-2,1,3,/vobs/atlas-idc/src/utils/logger/IDCLogger/IDC.cpp,48,19:16:46.523.231, 4 PS Sensor Value = -16.505000 , Min = -16.587000 , Max = -16.323000
PA43410-2,1,3,/vobs/atlas-idc/src/utils/logger/IDCLogger/IDC.cpp,48,19:16:46.523.263, 5 PS Sensor Value = 6.509000 , Min = 6.327000 , Max = 6.591000
PA43410-2,1,3,/vobs/atlas-idc/src/utils/logger/IDCLogger/IDC.cpp,48,19:16:46.523.302, 6 PS Sensor Value = 4.002000 , Min = 3.820000 , Max = 4.084000
PA43410-2,1,3,/vobs/atlas-idc/src/utils/logger/IDCLogger/IDC.cpp,48,19:17:46.481.557, 1 PS Sensor Value = 6.199000 , Min = 6.017000 , Max = 6.281000
PA43410-2,1,3,/vobs/atlas-idc/src/utils/logger/IDCLogger/IDC.cpp,48,19:17:46.518.691, 2 PS Sensor Value = -5.503000 , Min = -5.585000 , Max = -5.321000
PA43410-2,1,3,/vobs/atlas-idc/src/utils/logger/IDCLogger/IDC.cpp,48,19:17:46.523.156, 3 PS Sensor Value = 15.996000 , Min = 15.814000 , Max = 16.078000
PA43410-2,1,3,/vobs/atlas-idc/src/utils/logger/IDCLogger/IDC.cpp,48,19:17:46.523.195, 4 PS Sensor Value = -16.505000 , Min = -16.587000 , Max = -16.323000
PA43410-2,1,3,/vobs/atlas-idc/src/utils/logger/IDCLogger/IDC.cpp,48,19:17:46.523.221, 5 PS Sensor Value = 6.509000 , Min = 6.327000 , Max = 6.591000
PA43410-2,1,3,/vobs/atlas-idc/src/utils/logger/IDCLogger/IDC.cpp,48,19:17:46.523.240, 6 PS Sensor Value = 4.002000 , Min = 3.820000 , Max = 4.084000
PA43410-2,1,3,/vobs/atlas-idc/src/utils/logger/IDCLogger/IDC.cpp,48,19:18:46.480.644, 1 PS Sensor Value = 6.199000 , Min = 6.017000 , Max = 6.281000
PA43410-2,1,3,/vobs/atlas-idc/src/utils/logger/IDCLogger/IDC.cpp,48,19:18:46.522.615, 2 PS Sensor Value = -5.501000 , Min = -5.583000 , Max = -5.319000
PA43410-2,1,3,/vobs/atlas-idc/src/utils/logger/IDCLogger/IDC.cpp,48,19:18:46.522.729, 3 PS Sensor Value = 15.996000 , Min = 15.814000 , Max = 16.078000
PA43410-2,1,3,/vobs/atlas-idc/src/utils/logger/IDCLogger/IDC.cpp,48,19:18:46.522.765, 4 PS Sensor Value = -16.505000 , Min = -16.587000 , Max = -16.323000
PA43410-2,1,3,/vobs/atlas-idc/src/utils/logger/IDCLogger/IDC.cpp,48,19:18:46.522.788, 5 PS Sensor Value = 6.509000 , Min = 6.327000 , Max = 6.591000
PA43410-2,1,3,/vobs/atlas-idc/src/utils/logger/IDCLogger/IDC.cpp,48,19:18:46.522.810, 6 PS Sensor Value = 4.002000 , Min = 3.820000 , Max = 4.084000

I need to compare the PS Sensor Value, Min and Max value. (Min greater than PS Sensor greater than Max)

I'm expecting the output like below and here I should have only the normal lines.

What is normal lines? :
If Min value greater than PS Sensor value && PS Sensor value is greater than Max value then the line is normal lines and that should removed.

Expected Output:
PA43410-2 PS Sensor Value = 6.509000 , Min = 6.327000 , Max = 6.591000
PA43410-2 PS Sensor Value = 6.199000 , Min = 6.017000 , Max = 6.281000

Eg:

   If   Min < PS sensor value < Max,    // Don’t care the normal  lines.
         Throw this line away.
   Else  
        Pull this line to consolidated new file. //Only focus on abnormal lines.

Best Answer

A simple solution is to use awk. Since awk splits its input into fields on whitespace (by default), the PS sensor value will be field 7 ($7), the min will be $11 and the max will be $15. You can, therefore, do:

awk  '$7>$11 && $7<$15' file > new.file

The default action when an expression evaluates to true in awk is to print the current line. Therefore, the command above will print all lines whose 7th field is between the min and max values.

Related Question