drrehak 0 Posted September 10, 2010 hi, would love to pick your brains on this. I just cant get my data the way I need it. text file is: #id: 201 #name: Kevin #job: Nerd #id: 202 #name: Homer #job: Nuclear Engineer How do I rewrite this to: 201, Kevin, Nerd 202, Homer, Nuclear Engineer I have tried using openoffice transpose, but the list of fields is too long. I know I need to use an array, but need some guidance. thanks in advance! -Kevin Share this post Link to post Share on other sites
Mat 376 Posted September 10, 2010 $sString = StringRegExpReplace(FileRead($sFile), "\#id:\r\n(.*)\r\n\r\n\#name:\r\n(.*)\r\n\r\n\#job:\r\n(.*)(?:\r\n|\Z)", "\1, \2, \3") Not sure if it will like a huge list, but it'll do the job. AutoIt Project Listing Share this post Link to post Share on other sites
PsaltyDS 39 Posted September 10, 2010 Start with _FileReadToArray(). Then walk through the array with a For/Next loop. - If the current index $n is "#id" then start a new record line and the next index $n+1 is the first field, followed by a comma. - If the current index is blank ContinueLoop to the next line. - If the current index is "#name" then the next index is the second field to add to the line. - If the current index is "#job" then the next index is the last field, FileWriteLine() to the output file. You can do this. Take a shot at it and post your code for more help if you get stuck. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Share this post Link to post Share on other sites
drrehak 0 Posted September 13, 2010 thanks PSalty. that worked. I just had to step through the array. The problem is I have quite a few IF statements to find what I am looking for. Its a huge data file and I am capturing about 10 fields. Some of the fields are multiline too. that made it a little tricky. Share this post Link to post Share on other sites