1-获取字段索引

1-获取字段索引

这是我的输入文件:

PA43171-7,1,3,/vobs/atlas-idc/src/utils/logger/IDCLogger/IDC.cpp,48,12:01:16.086‌​.660, Valid Sensor Reading,Date = 08-19-2014 , Time = 12:01:16 Voltage Sensor=11 , V$ $=11 , Voltage Sensor Value=9.927417 , Min=9.450000 , Max=11.550000 

我需要比较电压传感器值、最小值和最大值。 (最小值大于电压传感器值大于最大值)

我期待输入文件的以下输出:

PA43171-7 Date = 08-19-2014 , Time = 12:01:16 Voltage Sensor Value=9.927417 , Min=9.450000 , Max=11.550000 

答案1

尝试

 awk -F, '{ printf "%s %s, %s %s %s µs\n",$1,$8,substr($9,1,15),$11,$12,$13 ;}' file

我使用获取字段位置

 awk -F, '{ for (i=1;i<=NF;i++) printf "%2d: %s\n",i,$i;}' a
 1: PA43171-7
 2: 1
 3: 3
 4: /vobs/atlas-idc/src/utils/logger/IDCLogger/IDC.cpp
 5: 48
 6: 12:01:16.086‌​.660
 7:  Valid Sensor Reading
 8: Date = 08-19-2014
 9:  Time = 12:01:16 Voltage Sensor=11
10:  V$ $=11
11:  Voltage Sensor Value=9.927417
12:  Min=9.450000
13:  Max=11.550000

编辑:(我看到重复的问题,这里没有白色周围=

1-获取字段索引

(仅对于第一行,我认为所有行看起来都相似)

awk 'BEGIN { FS="[,=]" } NR == 1 { for (i=1;i<=NF;i++) printf "%2d: %s\n",i,$i;}' a
 1: PA43171-7
 2: 1
 3: 3
 4: /vobs/atlas-idc/src/utils/logger/IDCLogger/IDC.cpp
 5: 48
 6: 12:01:16.086‌​.660
 7:  Valid Sensor Reading
 8: Date
 9:  08-19-2014
10:  Time
11:  12:01:16 Voltage Sensor
12: 11
13:  V$ $
14: 11
15:  Voltage Sensor Value
16: 9.927417
17:  Min
18: 9.450000
19:  Max
20: 11.550000

2-实际测试(根据如何使用 <(大于符号)比较字符串作为记录)

awk 'BEGIN { FS="[,=]" }
    $16 < $18 { print "too low:%s\n",$0 }
    $16 > $20 { print "too high:%s\n",$0 } ' a

相关内容