Passing bash variable to awk

前端 未结 2 527
北荒
北荒 2021-01-21 00:20

I\'m trying to extract a row/column element from a text table using awk within a function in bash. Specifically:

getel() {
    awk -v col=$3 \'FNR==$2 {print $c         


        
相关标签:
2条回答
  • 2021-01-21 00:38

    Or you could use bash variables directly:

    awk 'NR=='$2'{print $'$3'}' $1
    
    0 讨论(0)
  • 2021-01-21 00:59

    Pass another command line variable to awk:

    getel() {
        awk -v row=$2 -v col=$3 'NR==row {print $col }' $1
    }
    
    0 讨论(0)
提交回复
热议问题