Extract specific columns from delimited file using Awk

后端 未结 8 1886
-上瘾入骨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:36

    Other languages have short cuts for ranges of field numbers, but not awk, you'll have to write your code as your fear ;-)

    awk -F, 'BEGIN {OFS=","} { print $1, $2, $3, $4 ..... $30, $33}' infile.csv > outfile.csv
    

    There is no direct function in awk to use field names as column specifiers.

    I hope this helps.

提交回复
热议问题