How to print and store specific named columns from csv file with new row numbers

前端 未结 3 924
挽巷
挽巷 2021-01-24 22:40

start by saying, I\'m very new to using bash and any sort of script writing in general.

I have a csv file that has basic column headers and values underneath which look

3条回答
  •  青春惊慌失措
    2021-01-24 23:07

    If you have a simple multi-space delimited file (as in your example) awk is the best tool for the job. To select the column by name in awk you can do something like:

    $ awk -v col="b" 'FNR==1 { for (i=1;i<=NF;i++) if ($i==col) x=i; next }
                      {print FNR-1 OFS $x}' file   
    1 3
    2 5
    3 5
    4 8
    

提交回复
热议问题