Select row and element in awk

前端 未结 4 886
温柔的废话
温柔的废话 2021-01-29 18:17

I learned that in awk, $2 is the 2nd column. How to specify the ith line and the element at the ith row and jth column?

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-29 19:01

    To expand on Dennis's answer, use awk's -v option to pass the i and j values:

    # print the j'th field of the i'th line
    awk -v i=5 -v j=3 'FNR == i {print $j}'
    

提交回复
热议问题