小编Sha*_*thi的帖子

我需要一个 shell 脚本,通过将逗号保留在引号内,将 csv 文件转换为管道 (|) 分隔的文件

示例文件(test.csv):

"PRCD-15234","CDOC","12","JUN-20-2016 17:00:00","title, with commas, ","Y!##!"
"PRCD-99999","CDOC","1","Sep-26-2016 17:00:00","title without comma","Y!##!"
Run Code Online (Sandbox Code Playgroud)

输出文件:

PRCD-15234|CDOC|12|JUN-20-2016 17:00:00|title, with commas, |Y!##!
PRCD-99999|CDOC|1|Sep-26-2016 17:00:00|title without comma|Y!##!
Run Code Online (Sandbox Code Playgroud)

我的脚本(不起作用)如下:

while IFS="," read f1 f2 f3 f4 f5 f6; 
do  
    echo $f1|$f2|$f3|$f4|$f5|$f6;  
done < test.csv
Run Code Online (Sandbox Code Playgroud)

shell

2
推荐指数
1
解决办法
8234
查看次数

标签 统计

shell ×1