I am trying to work with awk
datetime=`date +\%Y\%m\%d`
logdatetime=`date +\%Y\%m\%d`
foldermonth=`date +\%B_\%Y`
folderday=`date +\%d`
inputdir="~/sboper/Standalone/fsplit/GLMS"
outputdir="~/sboper/StandAlone/input/$foldermonth"
outputdirday="~/sboper/StandAlone/input/$foldermonth/GLMS_Daily/$folderday"
awk -v outdir=$outputdirday 'BEGIN{ FS = "~" } ;{if( $12 == "A" ) filename="outdir/Customer_Create_Records.dat" ; print >> filename;close(filename)}' $inputdir/$sourcefile
awk -v outdir=$outputdirday 'BEGIN{ FS = "~" } ;{if( $12 == "M" ) filename="outdir/Customer_Modify_Records.dat" ; print >> filename;close(filename)}' $inputdir/$sourcefile
however the variable outdir=$outputdirday
is not expanding to the value of path which is my output directory.
I have declared the awk variable and did not use shell variable inside awk script. But its still giving me error: cannot open Customer_Create_Records.dat
.
Where am i going wrong with this script? When i copy complete path instead of 'outdir', it created new files and moved the record but doesnt work right when used in a variable. How can i create new files in the directory i want through awk?
$outputdirday
is correctly defined at that point? – Michael Vehrs Jun 07 '16 at 12:57date +\%Y\%m\%d
logdatetime=date +\%Y\%m\%d
foldermonth=date +\%B_\%Y
folderday=date +\%d
inputdir="~/sboper/Standalone/fsplit/GLMS" outputdir="~/sboper/StandAlone/input/$foldermonth" outputdirday="~/sboper/CMStandAlone/input/$foldermonth/GLMS_Daily/$folderday" – A.M. Jun 07 '16 at 13:06