Below command to split files is working fine when i provided absolute path for the output files "print > "/tmp/outputfile.txt"nfile}'" :
awk -v size=$(wc -l < inputfile.txt) -v perc=0.2 '{nfile = int(NR/(size*perc)); if(nfile >= 1/perc){nfile--; } print > "/tmp/outputfile.txt"nfile}' inputfile.txt
But when i removed absolute path with a variable it is not working, I have tried below commands -
printenv |grep tempdir
tempdir=/tmp
awk -v size=$(wc -l < inputfile.txt) -v perc=0.2 '{nfile = int(NR/(size*perc)); if(nfile >= 1/perc){nfile--; } print > ENVIRON["tempdir"]"outputfile.txt"nfile}' inputfile.txt
awk -v size=$(wc -l < inputfile.txt) -v perc=0.2 -v tempdir="/tmp" '{nfile = int(NR/(size*perc)); if(nfile >= 1/perc){nfile--; } print > "tempdir/outputfile.txt"nfile}' inputfile.txt
awk -v size=$(wc -l < inputfile.txt) -v perc=0.2 '{nfile = int(NR/(size*perc)); if(nfile >= 1/perc){nfile--; } print > "$tempdir/outputfile.txt"nfile}' inputfile.txt