使用shell指令碼替換csv檔案中的資料

进取發表於2024-05-29
[observer@xxx-grey-openresty test]$ cat file.csv
beijing,beijing,lisi,10
shanxi,xian,tom,6
shanghai,shanghai,xiaoming,3
guangdong,guangzhou,wangwu,8
sichuan,chengdu,cat,5
[observer@xxx-grey-openresty test]$ awk -F, -v OFS=, '$4 > 5 {$4 = 3} {print}' file.csv
beijing,beijing,lisi,3
shanxi,xian,tom,3
shanghai,shanghai,xiaoming,3
guangdong,guangzhou,wangwu,3
sichuan,chengdu,cat,5
[observer@xxx-grey-openresty test]$

將輸出結果儲存到檔案中

awk -F, -v OFS=, '$4 > 5 {$4 = 3} {print}' file.csv  > result.csv

相關文章