简体   繁体   English

使用 shell 变量到 select awk 列标识符

[英]Using shell variable to select awk column identifier

This one works:这个有效:

temp=($(awk -F" "  '$2 == 84' "$1".db))

This one does not (fieldnumber stores the column i wish to search, and val stores the value I'm searching for):这个没有(fieldnumber 存储我要搜索的列,而 val 存储我正在搜索的值):

temp=($(awk -F" " -v column="$""$field_number" -v val="$3" '{ if(column == val) print $0;}' "$1".db))

I am trying to manipulate the awk command based on command line inputs within shell script: ./dr.sh cop4342 exam1 84 (84 is the value to be searched for) (exam1 is used within the shell script to find the column number)我正在尝试根据 shell 脚本中的命令行输入来操作 awk 命令: ./dr.sh cop4342 exam1 84 (84 是要搜索的值)(exam1 在 shell 脚本中用于查找列号)

代码图像代码输出

This is terribly unclear, but I guess you are looking for这非常不清楚,但我想你正在寻找

temp=($(awk -F " " -v column="$field_number" \
            -v val="$3" '{ if($column == val) print $0;}' "$1".db))

which of course can be simplified to just这当然可以简化为

temp=($(awk -v column="$field_number" \
            -v val="$3" '$column == val' "$1".db))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM