Bash: Parse CSV with quotes, commas and newlines

前端 未结 7 1650
隐瞒了意图╮
隐瞒了意图╮ 2020-12-11 16:10

Say I have the following csv file:

 id,message,time
 123,\"Sorry, This message
 has commas and newlines\",2016-03-28T20:26:39
 456,\"It makes the problem non         


        
7条回答
  •  旧时难觅i
    2020-12-11 16:30

    another awk alternative using FS

    $ awk -F'"' '!(NF%2){getline remainder;$0=$0 OFS remainder}
                    NR>1{sub(/,/,"",$NF); print $NF}' file
    
    2016-03-28T20:26:39
    2016-03-28T20:26:41
    

提交回复
热议问题