drrehak Posted September 10, 2010 Share 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 Link to comment Share on other sites More sharing options...
Mat Posted September 10, 2010 Share 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 Link to comment Share on other sites More sharing options...
PsaltyDS Posted September 10, 2010 Share 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 Link to comment Share on other sites More sharing options...
drrehak Posted September 13, 2010 Author Share 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. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now