Using for or while loops

Posted by Gary on Stack Overflow See other posts from Stack Overflow or by Gary
Published on 2010-04-08T18:59:13Z Indexed on 2010/04/08 19:03 UTC
Read the original article Hit count: 466

Filed under:

Every month, 4 or 5 text files are created. The data in the files is pulled into MS Access and used in a mailmerge.

Each file contains a header. This is an example: HEADER|0000000130|0000527350|0000171250|0000058000|0000756600|0000814753|0000819455|100106

The 2nd field is the number of records contained in the file (excluding the header line). The last field is the date in the form yymmdd.

Using gawk (for Windows), I've done ok with rearranging/modifying the data and writing it all out to a new file for importing into Access except for the following.

I'm trying to create a unique ID number for each record. The ID number has the form 1mmddyyXXXX, where XXXX is a number, padded with leading zeros. Using the header above, the first record in the output file would get the ID number 10106100001 and the last record would get the ID 10106100130.

I've tried putting the second field in the header into a variable, rearranging the last header field into the required date format and then looping with "for" statements to append the XXXX part of the ID and then outputting it all with printf but so far I've been complete rubbish at it.

Thanks for your help! gary

© Stack Overflow or respective owner

Related posts about awk