我的abc1.log包含内容:
length: 2.3 %
Internal breadth value (for calculation only): 63205 (including size \
Internal area after transforming (for calculation only): 53000 (including type \
Internal depth after cleaning and drying (for calculation only): 33221 (including area \
包含内容的abc2.log:
length: 3.9 %
Internal breadth value (for calculation only): 74605 (including size \
Internal area after transforming (for calculation only): 23330 (including type \
Internal depth after cleaning and drying (for calculation only): 99237 (including area \
我正在使用csh脚本来提取符号后面每行中看到的数值:在abc1.log和abc2.log中,比较它们并打印一个消息。
#! /bin/csh
### case1
set length_abc1=`awk '{for(i=1;i<=NF;i++) if ($i=="length:") print $(i+1)}' abc1.log | bc`
set length_abc2=`awk '{for(i=1;i<=NF;i++) if ($i=="length:") print $(i+1)}' abc2.log | bc`
if ($length_abc1:q > $length_abc2:q) then
echo $length_abc1
echo $length_abc2
echo "ERROR: value of length_abc1 is greater than length_abc2"
else
echo $length_abc1
echo $length_abc2
echo "PASS: value of length_abc1 is smaller than length_abc2"
endif
上面的case1代码遇到错误,如果:编号错误
### case2
set breadth_area_depth_abc1=`awk '{for(i=1;i<=NF;i++) if ($i=="only):") print $(i+1)}' abc1.log`
set breadth_area_depth_abc2=`awk '{for(i=1;i<=NF;i++) if ($i=="only):") print $(i+1)}' abc2.log`
if ($breadth_area_depth_abc1:q > $ breadth_area_depth_abc2:q) then
echo $breadth_area_depth_abc1
echo $breadth_area_depth_abc2
echo "ERROR: value of breadth_area_depth_abc1 is bigger"
else
echo $breadth_area_depth_abc1
echo $breadth_area_depth_abc2
echo "PASS: value of breadth_area_depth_abc1 is smaller"
endif
上面的case2代码遇到错误,如果:表达式语法
在case2中,变量breadth_area_depth_area1,变量breadth_area_depth_area2将具有诸如63205 53000 33221和74605 23330 99237的值。
我想将数值63205与74605,53000与23330,33221与99237进行比较并打印msgs。如果用一个变量或三个变量实现,我就没问题。 我甚至尝试使用下面的方法来捕获breadth_area_depth_abc1中的63205数值(参见abc1.log中的第2行),但这也不起作用。
set breadth_area_depth_abc1=`awk '{for(i=1;i<=NF;i++) if ($i==" value (for calculation only):") print $(i+1)}' abc1.log`