在csv文件中我有以下列,我尝试用
更改第二列的值$ awk -v FS="\",\"" -v OFS="\",\"" '{$2=sprintf("%.2f",$2*2)}1' file.csv
但是有些列包含必须保持不变的字符串。我知道了
"^[0-9][0-9]*$"
会检查它是否是数字,但是如何在我的命令中将它合并?
FILE.CSV
"sku","NO price","supplierName"
"sku","3.14","supplierName"
"sku","3.56","supplierName"
"sku","4.20","supplierName"
答案 0 :(得分:1)
您可以使用:
awk -v FS='","' -v OFS='","' '$2+0 == $2{$2=sprintf("%.2f",$2*2)}1' file.csv
"sku","NO price","supplierName"
"sku","6.28","supplierName"
"sku","7.12","supplierName"
"sku","8.40","supplierName"
$2+0 == $2
检查确保$2
中的值为数字。