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

前端 未结 3 925
挽巷
挽巷 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:22

    Like this? Using awk:

    $ awk 'NR>1{print NR-1, $2}' file
    1 3
    2 5
    3 5
    4 8
    

    Explained:

    $ awk '              # using awk for the job
    NR>1 {               # for the records or rows after the first
        print NR-1, $2   # output record number minus one and the second field or column
    }' file              # state the file
    

    I would like to be able to do this for various different named column headers. With awk you don't specify the column header name but the column number, like you don't state b but $2.

提交回复
热议问题