bash里,在awk print里面使用变量

Publish: May 14, 2014 Category: Shell 1 Comment

#!/bin/bash
#exampel inputfile is "myfile.txt"
inputfile=$1
basen=`basename $inputfile .txt`

# The -v flag is for setting variables from the command line. Try something like this:
awk -v "BASEN=$basen" '{print BASEN "\t" $3}'