I want to receive a value back into shell script from awk code block.
for example - I want to use the substring value from the awk script inside the shell code's scope.
do
dir=`dirname $file`;
echo | awk '{print substr("'"${dir}"'",'$pathlength')}';
done
can someone guide me how to do that?
any pointers appreciated.
thanks,
Iyer
gnsxhj
2
well, i dont know if it is what u want :
echo `echo | awk '{print substr("'"$dir"'","'"$pathlength"'")}'`
or:
var=`echo | awk '{print substr("'"$dir"'","'"$pathlength"'")}'`
era
3
You already know how to use backticks. Just put the awk commands in backticks as well.
For bonus points, assuming you don't need the output from dirname other than to pass to awk, maybe something like
dir=`dirname "$file" | awk -v pathlength=$pathlength '{ print substr($0, pathlength) }'
It's not clear where you are expecting $pathlength to come from, but let's assume you can handle that.