Parse a csv using awk and ignoring commas inside a field

前端 未结 7 1134
抹茶落季
抹茶落季 2020-11-29 04:36

I have a csv file where each row defines a room in a given building. Along with room, each row has a floor field. What I want to extract is all floors in all buildings. <

相关标签:
7条回答
  • 2020-11-29 05:11

    You can use a script I wrote called csvquote to let awk ignore the commas inside the quoted fields. The command would then become:

    csvquote Buildings.csv | awk -F, '{print $1","$2}' | sort | uniq | csvquote -u > Floors.csv
    

    and cut might be a bit easier than awk for this:

    csvquote Buildings.csv | cut -d, -f1,2 | sort | uniq | csvquote -u > Floors.csv
    

    You can find the csvquote code here: https://github.com/dbro/csvquote

    0 讨论(0)
提交回复
热议问题