Select row and element in awk

前端 未结 4 928
温柔的废话
温柔的废话 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:17

    To print the columns with a specific string, you use the // search pattern. For example, if you are looking for second columns that contains abc:

    awk '$2 ~ /abc/'
    

    ... and if you want to print only a particular column:

    awk '$2 ~ /abc/ { print $3 }'
    

    ... and for a particular line number:

    awk '$2 ~ /abc/ && FNR == 5 { print $3 }'
    

提交回复
热议问题