入力データに対して数学演算を実行して印刷しますか? [閉鎖]

入力データに対して数学演算を実行して印刷しますか? [閉鎖]

以下のように、bashスクリプトを使用して行と列ごとにデータを印刷しようとしています。

#!/bin/bash
while IFS='' read -r line || [[ -n "$line" ]]; do
    echo "$line"
done < "$1" 
{ 
   awk 'BEGIN { print "Points"}
      /Points/ { id = $1; }'
} 

私のtxtファイルは次のとおりです。

Team    Played  Wins    Tied
england     4       3       2
america     9       5       3

端末の出力は次のようになります。

Team    Played  Wins    Tied  Points
england    4        3       2     16
america     9       5       3     26

計算は次のとおりです。チームが1勝を収めれば勝点4点、引き分けは勝点2点を獲得します。ところで、数学をどうするのか分からないのでできません。

ベストアンサー1

これにはシェルループはまったく必要ありません。

awk '{$(NF+1) = NR==1 ? "Points" : $3*4 + $4*2; print}' OFS='\t' input.txt
Team    Played  Wins    Tied    Points
A       2       1       1       6
B       2       0       1       2

おすすめ記事