创建的变量我有脚本,看起来像这样如何使AWK使用bash脚本
#!/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调用之前创建的“倍欣”的变量。但不知怎的,它没有做到我希望的那样。
因此,例如myfile.txt
包含这些线路
foo bar bax
foo qux bar
通过上述bash脚本我希望得到
myfile bax
myfile bar
怎样做正确的方式?
使用'$()'而不是反引号。用'for for'循环''find'就会发现它会打破空间文件。引用你的'$ 1'变量 – ghostdog74 2010-06-23 05:44:16