我有一个表resultat.csv
,它看起来像这样:
20.7 120.4 -80
-10.1 78 -155
5.44 32.4 43.9
我试图做的是:
在的每一行 resultat.csv
if the value of the 1st column is less or equal to 0 then you pick the
value from column 3
其他
if the value of the 1st column is greater than 0 then you pick the
value from column 2
第一列的值是一个可以为负的十进制数。
这是我的代码:
awk -F " " ' {print $1}' resultat.csv | while IFS=, read -r k
do
status=$(echo "$k <= 0" | bc)
if [[ $status -eq 1 ]];then
grep -- $k resultat.csv | awk -F ' ' '{print $3}'
elif [[ $status -eq 0 ]];then
grep -- $k resultat.csv | awk -F ' ' '{print $2}'
fi
done > Y.csv
但是它没有给出错误,但是没有给出我的预期输出
120.4
-155
32.4
我使用的grep不能从第1列捕获值,resultat.csv
但所有值看起来都是这样。
有什么建议吗?
只需简单地执行所有操作即可。
awk '{ if ($1 > 0) print $2; else print $3 }' resultat.csv
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句