Should I use AWK or SED to remove commas between quotation marks from a CSV file? (BASH)

后端 未结 2 431
既然无缘
既然无缘 2021-01-26 16:31

I have a bunch of daily printer logs in CSV format and I\'m writing a script to keep track of how much paper is being used and save the info to a database, but I\'v

2条回答
  •  南笙
    南笙 (楼主)
    2021-01-26 17:01

    As I wrote in another answer:

    Rather than interfere with what is evidently source data, i.e. the stuff inside the quotes, you might consider replacing the field-separator commas (with say |) instead:

    s/,([^,"]*|"[^"]*")(?=(,|$))/|$1/g
    

    And then splitting on | (assuming none of your data has | in it).

    Is it possible to write a regular expression that matches a particular pattern and then does a replace with a part of the pattern

提交回复
热议问题