Issue
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.
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.
So for example myfile.txt
contain these lines
foo bar bax
foo qux bar
With the above bash script I hope to get
myfile bax
myfile bar
What's the right way to do it?
Solution
You can use it like this.
for i in `find $1 -name \*.jar`
do
jar tvf $i| awk -F '/' '/class/{print "'${i}'" " " $NF }' >> $classFile
done
You should use
"'${i}'"
in AWK to use the
$i
created in Bash Script.
Answered By - iamxhu Answer Checked By - Mary Flores (WPSolving Volunteer)