parse a csv file that contains commans in the fields with awk

后端 未结 4 915
独厮守ぢ
独厮守ぢ 2021-02-05 10:47

i have to use awk to print out 4 different columns in a csv file. The problem is the strings are in a $x,xxx.xx format. When I run the regular awk command.

awk -         


        
4条回答
  •  孤独总比滥情好
    2021-02-05 11:23

    The data file:

    $ cat data.txt
    "$307.00","$132.34","$30.23"
    

    The AWK script:

    $ cat csv.awk
    BEGIN { RS = "," }
    { gsub("\"", "", $1);
      print $1 }
    

    The execution:

    $ awk -f csv.awk data.txt
    $307.00
    $132.34
    $30.23
    

提交回复
热议问题