Extract specific columns from delimited file using Awk

后端 未结 8 1900
-上瘾入骨i
-上瘾入骨i 2020-11-28 05:44

Sorry if this is too basic. I have a csv file where the columns have a header row (v1, v2, etc.). I understand that to extract columns 1 and 2, I have to do: awk -F \

8条回答
  •  暖寄归人
    2020-11-28 06:25

    Not using awk but the simplest way I was able to get this done was to just use csvtool. I had other use cases as well to use csvtool and it can handle the quotes or delimiters appropriately if they appear within the column data itself.

    csvtool format '%(2)\n' input.csv
    csvtool format '%(2),%(3),%(4)\n' input.csv
    

    Replacing 2 with the column number will effectively extract the column data you are looking for.

提交回复
热议问题