Posting from the Informix-list
Posted in 2000
This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_000_01BF8CF5.F5921632 Content-Type: text/plain; charset="iso-8859-1" <<grpride.ksh>> Can someone please take a look at this and tell be what I'm doing wrong? This is really an awk question, but I posted to the awk group and the suggestion I was given didn't work. I'm really missing something here with using functions and arrays. What I am trying to do in the script is create an julian day based on the 5th field and insert this value in the 6th field when the 6th field is blank. Cheryl Kemp Senior Data/Database Analyst Coventry Health Care Phone: (724) 778-6487 ------_=_NextPart_000_01BF8CF5.F5921632 Content-Type: application/octet-stream; name="grpride.ksh" Content-Disposition: attachment; filename="grpride.ksh" #!/bin/ksh # Find name of input file for employer_grp_rider table #DWT_FILE=`egrep 'DWT' *.dwh | nawk -F^ '{printf tolower($1)}'` DWD_FILE=mcadwd DWD_FILE_COPY=$DWD_FILE.orig DWD_FILE_WORK=$DWD_FILE.work # Make copy of original file (backup) and make working copy of file. Sort it and write it out back to the original file cp $DWD_FILE $DWD_FILE_COPY sort $DWD_FILE_COPY -t ^ +1n -2 +4n -5 +2 -3 +0n -1 +3 -4 > $DWD_FILE_WORK # Meat of program - nawk script nawk 'BEGIN { FS="^"; } function ToJul( date, jul_day ) { spdate=split($5, datum, "/" ) lmonth = datum[1] lday = datum[2] lyear = datum[3] if ( lyear < 80 ) lyear += 2000 else if ( lyear < 100 ) lyear += 1900 jul_day = lday - 32076 + 1461 * (lyear + 4800 + int(int((lmonth - 14)\\ / 12) / 4 \\ )) \\ + 367 * int((lmonth - 2 - int((lmonth - 14) / 12) * 12) / 12 ) - \\ 3 * \\ int(int((lyear + 4900 + int((lmonth - 14) / 12)) / 100) / 4 ) \\ ret jul_day} function prt_emp_buff(emp_buff, loop) { OFS="" for (loop = 1; loop <= numfields; ++loop) { printf (OFS"%s", emp_buff[loop]) OFS="^" } printf "\\n" } NR == 1 { numfields=split($0, emp_buff) next } $1 == emp_buff[1] && $2 == emp_buff[2] && $3 == emp_buff[3] && $5 == emp_buff[5] && ! emp_buff[6] { emp_buff[6] = (ToJul(jul_day)) echo emp_buff[6] } { prt_emp_buff(emp_buff) numfields=split($0, emp_buff) } END { prt_emp_buff(emp_buff) } '# $DWD_FILE_WORK > $DWD_FILE #/usr/bin/rm $DWD_FILE_WORK chmod 777 $DWD_FILE ------_=_NextPart_000_01BF8CF5.F5921632--