分页: 1 / 1
[问题]gawk的问题
发表于 : 2007-10-28 14:27
由 bilyecit
declare temp
declare search_key
...
执行
temp=$(gawk"\$2 ~ /$search_key/ {print $3}" file)
为什么temp得不到$3的值
而
gawk"\$2 ~ /$search_key/ {print $3}" file
能输出正确的结果
谢
发表于 : 2007-10-28 19:43
由 悬非
echo $temp
发表于 : 2007-10-28 21:03
由 bilyecit
悬非 写了:echo $temp
echo $temp输出为空
发表于 : 2007-10-28 22:54
由 悬非
你把整个脚本贴出来看看
发表于 : 2007-10-28 22:57
由 eexpress
gawk"\$2 ~ /$search_key/ {print $3}" file
用``包括吧。这是shell里面,还是awk脚本里面啊。
发表于 : 2007-10-29 11:32
由 bilyecit
eexpress 写了:gawk"\$2 ~ /$search_key/ {print $3}" file
用``包括吧。这是shell里面,还是awk脚本里面啊。
可能是我没有表述清楚意思
我是想
查找file文件中某行第二字段的值等于search_key的值(用户输入),并将该行第三字段的值赋给temp变量
发表于 : 2007-11-01 23:41
由 悬非
bilyecit 写了:eexpress 写了:gawk"\$2 ~ /$search_key/ {print $3}" file
查找file文件中某行第二字段的值等于search_key的值(用户输入),并将该行第三字段的值赋给temp变量
代码: 全选
~# cat xuanfei
hi welcom
hi linux good
yes
~# zz=$(awk '$2 ~/linux/ print $3}' xuanfei) awk: $2 ~/linux/ print $3}
~# zz=$(awk '$2 ~/linux/ {print $3}' xuanfei)
~# echo $zz
good
~#