参见英文答案 > How do I use shell variables in an awk script? 7个
我的脚本看起来像这样
#!/bin/bash
#exampel inputfile is "myfile.txt"
inputfile=$1
basen=`basename $inputfile .txt` # create basename
cat $inputfile |
awk '{print $basen "\t" $3} # this doesn't print "myfile" but the whole content of it.
我上面要做的是在AWK中打印之前创建的名为“basen”的变量.
但不知怎的,它未能按照我的希望做到.
例如,myfile.txt包含这些行
foo bar bax
foo qux bar
使用上面的bash脚本我希望得到
myfile bax
myfile bar
什么是正确的方法呢?
解决方法:
你可以像这样使用它.
for i in `find $1 -name \*.jar`
do
jar tvf $i| awk -F '/' '/class/{print "'${i}'" " " $NF }' >> $classFile
done
你应该用
“‘${i}'”
在AWK中使用
$i
在Bash脚本中创建.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。