IFS separate a string like “Hello”,“World”,“this”,“is, a boring”, “line”

前端 未结 3 1566
夕颜
夕颜 2021-01-29 07:10

I\'m trying to parse a .csv file and I have some problems with IFS. The file contains lines like this:

\"Hello\",\"World\",\"this\",\"is, a boring\",\"line\"
         


        
3条回答
  •  借酒劲吻你
    2021-01-29 07:33

    You may wish to use the gawk with FPAT to define what makes a valid string -

    Input :

    "hello","world","this,is"

    Script :

    gawk -n 'BEGIN{FS=",";OFS="\n";FPAT="([^,]+)|(\"[^\"]+\")"}{$1=$1;print $0}' somefile.csv
    

    Output :

    "hello"
    "world"
    "this,is"

提交回复
热议问题