大家好,原谅我的英语不好。我设法在代码中使用列程序很好地、整齐地显示我的数据。但是我如何在价格栏中添加“$”。其次,我如何向它添加一个新的列总和并用“$”显示它。 (价格 * 已售出)
(echo "Title:Author:Price:Quantity:Sold" && cat BookDB.txt) | column -s: -t
输出:
Title Author Price Quantity Sold
The Godfather Mario Puzo 21.50 50 20
The Hobbit J.R.R Tolkien 40.50 50 10
Romeo and Juliet William Shakespeare 102.80 200 100
The Chronicles of Narnia C.S.Lewis 35.90 80 15
Lord of the Flies William Golding 29.80 125 25
Memories of a Geisha Arthur Golden 35.99 120 50
最佳答案
我想你可以用 awk 来做(在 &&
之前添加换行符以提高可读性
(echo "Title:Author:Price:Quantity:Sold:Calculated"
&& awk -F: '{printf ("%s:%s:$%d:%d:%d:%d\n",$1,$2,$3,$4,$5,$3*$5)}' BookDB.txt) | column -s: -t
关于将 "$"插入格式化列并添加新列的 shell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28145059/