如何使AWK使用Bash脚本中创建的变量 [英] How to make AWK use the variable created in Bash Script
本文介绍了如何使AWK使用Bash脚本中创建的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个看起来像这样的脚本
I have script that looks like this
#!/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'的变量. 但是不知何故,它未能实现我希望的目标.
What I want to do above is to print out in AWK the variable called 'basen' created before. But somehow it failed to do what I hoped it will.
例如,myfile.txt
包含这些行
foo bar bax
foo qux bar
我希望通过上述bash脚本获得
With the above bash script I hope to get
myfile bax
myfile bar
什么是正确的方法?
推荐答案
您可以像这样使用它.
for i in `find $1 -name \*.jar`
do
jar tvf $i| awk -F '/' '/class/{print "'${i}'" " " $NF }' >> $classFile
done
您应该使用
'$ {i}'"
"'${i}'"
在AWK中使用
$ i
$i
在Bash脚本中创建.
created in Bash Script.
这篇关于如何使AWK使用Bash脚本中创建的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文