shell 将“$”插入格式化列并添加新列的脚本
shell script inserting "$" into a formatted column and adding new column
大家好,请原谅我的英语不好。我设法在代码中使用列程序很好地整齐地显示了我的数据。但是我如何在价格栏中添加一个“$”。其次我如何向它添加一个新的列总和并用“$”显示它。 (价格 * 已售出)
(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",,,,,,*)}' BookDB.txt) | column -s: -t
大家好,请原谅我的英语不好。我设法在代码中使用列程序很好地整齐地显示了我的数据。但是我如何在价格栏中添加一个“$”。其次我如何向它添加一个新的列总和并用“$”显示它。 (价格 * 已售出)
(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",,,,,,*)}' BookDB.txt) | column -s: -t