if [ -f $filepath3 ]; #will print header columns properties file. print $header >$cfilepath3 #to add rows in output file input file . awk -f\" 'begin{ofs=fs;} {for(i=1;i<=nf;i=i+2){gsub(/,/,"~\t",$i);}}1' $filepath3 > $tfilepath3 #removes footer,header , prints columns per mapping picking column numbers properties file cat $tfilepath3| sed '1d' | awk 'begin { fs = "~\t"; ofs = ",";}{ date = date -d "$'$ms2'" "+%y%m%d" } { printf "%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s\n", $'$ms1', $date,$'$ms3',$'$ms4',$'$ms5',$'$ms6',$'$ms7',$'$ms8’,”ms”,$’$ms10',$'$ms11',$'$ms12',$'$ms13',$'$ms14',$'$ms15',$'$ms16',$'$ms17'}' >> $cfilepath3
in above code, i'm trying copy data input file output file. ms1, ms2 column positions of csv input file.
ms2 date format mm/dd/yyyy , considered variable. need convert variable yyyymmdd format , write output file
in script i'm trying change date format yyyymmdd.. i'm getting error.
i think error code
{ date = date -d "$'$ms2'" "+%y%m%d" }
you trying access variable in single quotes , wont happen, try use following syntax.
date=$(echo $ms2|awk -f '/' '{print $3$2$1}') cat $tfilepath3| sed '1d' | awk -v ms2="$date" 'begin { fs = "~\t"; ofs = ",";} { printf "%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s\n", $'$ms1', $ms2,$'$ms3',$'$ms4',$'$ms5',$'$ms6',$'$ms7',$'$ms8’,”ms”,$’$ms10',$'$ms11',$'$ms12',$'$ms13',$'$ms14',$'$ms15',$'$ms16',$'$ms17'}' >> $cfilepath3
Comments
Post a Comment