我有一个像这样的奇怪的CSV文件
"asdf",,,"asdf","asdf"asdf"
我希望将逗号转换为标签(出于个人原因)
我希望能做到这样的事情:
perl -ne 's/",+"/\t/g && print'
预期产出
"asdf[tab][tab][tab]asdf[tab]asdf"asdf"
但是只用一个逗号替换一个标签,我需要为3个标签设置3个逗号。有没有办法计算其中一个存在量词(+或*)中的匹配数,并使用它来确定我应该打印多少个标签
我可以处理开头和结尾的引号,除非有人想要抛弃它们。
答案 0 :(得分:3)
答案 1 :(得分:0)
That replaces all commas with one tab, because you are using ,+
and asking it to match all commas in one go.
Your code:
perl -ne 's/",+"/\t/g && print'
Problem is the "+". It takes multiple of whatever
I changed it to:
perl -ne 's/,/\t/g && print'
and it worked fine:
"asdf" "asdf" "asdf "asdf"