![打印表格中的数字](https://linux22.com/image/154024/%E6%89%93%E5%8D%B0%E8%A1%A8%E6%A0%BC%E4%B8%AD%E7%9A%84%E6%95%B0%E5%AD%97.png)
请问如何从这个表中得到四个数字?原始输入较长,因此需要限制区域。
输入:
chil 2 44843.084886752418 44843.080972494339 0.38261625919046571
o 0 1 0 1 1 5.732820000 0.000 = PERIOD(0)
o 0 2 0 1 1 54002.864912732 0.000 = PERIASTRON EPOCH
o 0 3 0 1 1 0.086796671 0.000 = ECCENTRICITY
o 0 4 0 1 1 151.562809500 0.020 = PERIASTRON LONG.
o 0 5 0 1 1 107.927001263 0.053 = K1
o 0 6 0 1 1 0.418206121 0.000 = q = M2/M1, K2 = 258.071309
o 0 7 0 1 1 0.004220000 0.000 = d omega/dt
o 0 8 0 1 1 0.000000000 0.100 = d P/dt
o 0 9 0 1 1 0.000000000 0.100 = d e/dt
o 0 10 0 1 1 0.000000000 0.100 = d K1/dt
o 0 11 0 1 1 0.000000000 0.100 = d q/dt
o 2 1 0 1 1 99000.000000000 1650.000 = PERIOD(2)
o 2 2 0 1 1 39254.892879388 -984.000 = PERIASTRON EPOCH
o 2 3 0 1 1 0.770000000 0.010 = ECCENTRICITY
o 2 4 0 1 1 68.284996369 -6.000 = PERIASTRON LONG.
所需输出
0.086796671
151.562809500
107.927001263
0.418206121
我尝试失败
/o 0 1 0 1 1 5.732820000 0.000 = PERIOD(0)/ { c=FNR;}
(FNR-c>=2 && c>0) {$2 ~ /\<0\>/ $3 ~ /\<3|4|5|6\>/ { print $7}
我想说:如果第二列是0,第三列是3,4,5,6打印第7列
答案1
awk '$2==0 && $3~/^[3456]$/{print $7}' data
更新
限制到特定区域:
awk '/o 0 1 0 1 1 5.732820000 0.000 = PERIOD\(0\)/ {b=1}
b && $2==0 && $3~/^[3456]$/{print $7}
b && $3==6 { b=0 }' data