各列にテキストを追加[重複]

各列にテキストを追加[重複]

私は次の行を持っています

3, 3, 100
4, 2, 50
8, 5, 80
.
.
.

私は次のような出力が欲しい

line starts at 3 and ends at 3 with value 100
line starts at 4 and ends at 2 with value 50
line starts at 8 and ends at 5 with value 80
.
.
.

以下を試しました。sed 's/^/line starts at /'その後、このコマンドを出力に適用しました。sed 's/, / and ends at /'その後、このコマンドを出力に適用しましたsed 's/, / with value /'。一行にできる方法はないでしょうか?

ベストアンサー1

awkこのフォーマットされた入力の場合、フォーマットされた出力は便利です。

awk -F, '{printf("line starts at %d and ends at %d with value %d\n", $1, $2, $3)}' file 
line starts at 3 and ends at 3 with value 100
line starts at 4 and ends at 2 with value 50
line starts at 8 and ends at 5 with value 80

おすすめ記事