lhk69 Posted August 1, 2011 Posted August 1, 2011 (edited) ok, again, I have to admit ignorance. I am new and not sure how I want to do this or how to get it done. I want to read through this text file. For each SEVER_NAME - I want to get the CURRENT_GROUP and the steps it went through and when. I have most of it. Now, I need to get to a delimited format with all 15 steps. Whether they are there are not. The current code will produce a delimited output of all the steps and dates, but I need it to put place holders for the steps that aren’t there. So when I output it to excel, all of the STEP1's are in the same column and so on. I am trying to create a temp array each time through the loop and populate it with the steps. Wrong??? CURRENT CODE expandcollapse popup#include <File.au3> #include <array.au3> #include <String.au3> #include <Date.au3> Global $FileArray, $OutputLine, $textStageDate[1], $OutArray[16] Global $InputFile = "c:\documents and settings\v-kleinl\desktop\report.rep" Func Fix_Date_1($input) ;Replace comma with space Local $temp0 = StringReplace($input, ",", "") ;Remove the DAY If StringLeft($temp0, 3) = "Mon" Then Local $temp1 = StringReplace($temp0, "Monday ", "") EndIf If StringLeft($temp0, 3) = "Tue" Then Local $temp1 = StringReplace($temp0, "Tuesday ", "") EndIf If StringLeft($temp0, 3) = "Wed" Then Local $temp1 = StringReplace($temp0, "Wednesday ", "") EndIf If StringLeft($temp0, 3) = "Thu" Then Local $temp1 = StringReplace($temp0, "Thursday ", "") EndIf If StringLeft($temp0, 3) = "Fri" Then Local $temp1 = StringReplace($temp0, "Friday ", "") EndIf If StringLeft($temp0, 3) = "Sat" Then Local $temp1 = StringReplace($temp0, "Saturday ", "") EndIf If StringLeft($temp0, 3) = "Sun" Then Local $temp1 = StringReplace($temp0, "Sunday ", "") EndIf ;Split up result into array Local $temp = StringSplit($temp1, " ") ;Convert Month into a numeric value Local $month = StringSplit("Jan,Feb,Mar,Apr,May,June,July,Aug,Sept,Oct,Nov,Dec", ",") For $x = 1 To 12 If StringInStr($temp[1], $month[$x]) Then Return $x & "/" & $temp[2] & "/" & $temp[3] & " " & $temp[4] & " " & $temp[5] Next Return SetError(1, 0, -1) EndFunc ;==>Fix_Date_1 Func Fix_Date_2($input) ;Replace comma with space Local $temp0 = StringReplace($input, ".", " ") ;Split up result into array Local $temp = StringSplit($temp0, " ") ;_ArrayDisplay($temp) Return $temp[2] & "/" & $temp[3] & "/" & $temp[1] & " " & $temp[5] Return SetError(1, 0, -1) EndFunc Func Fix_Date($input) If StringLeft($input, 5) = "2011." Then $FixedDate = Fix_Date_2($input) $textStageDate[0] = $FixedDate EndIf If StringLeft($input, 3) = "Mon" Then $FixedDate = Fix_Date_1($input) $textStageDate[0] = $FixedDate EndIf If StringLeft($input, 3) = "Tue" Then $FixedDate = Fix_Date_1($input) $textStageDate[0] = $FixedDate EndIf If StringLeft($input, 3) = "Wed" Then $FixedDate = Fix_Date_1($input) $textStageDate[0] = $FixedDate EndIf If StringLeft($input, 3) = "Thu" Then $FixedDate = Fix_Date_1($input) $textStageDate[0] = $FixedDate EndIf If StringLeft($input, 3) = "Fri" Then $FixedDate = Fix_Date_1($input) $textStageDate[0] = $FixedDate EndIf If StringLeft($input, 3) = "Sat" Then $FixedDate = Fix_Date_1($input) $textStageDate[0] = $FixedDate EndIf If StringLeft($input, 3) = "Sun" Then $FixedDate = Fix_Date_1($input) $textStageDate[0] = $FixedDate EndIf EndFunc If Not _FileReadToArray($InputFile, $FileArray) Then MsgBox(0, "Error", "Unable to open Input file.") Exit EndIf $OutputFile = FileOpen("c:\documents and settings\v-kleinl\desktop\results.csv", 10) If $OutputFile = -1 Then MsgBox(0, "Error", "Unable to open Output file.") Exit EndIf For $LineNumber = 1 To $FileArray[0] ; Read each line ;Find a line with "Server Name" on it and just return the SERVER NAME If StringLeft($FileArray[$LineNumber], 14) = "Server Name : " Then FileWrite($OutputFile, $OutputLine & @CRLF) $OutputLine = StringMid($FileArray[$LineNumber], 15, 15) & "," EndIf ;Then find a line with "Current Group" on it and just return the GROUP NAME and add it to the output line If StringLeft($FileArray[$LineNumber], 16) = "Current Group : " Then $OutputLine &= StringMid($FileArray[$LineNumber], 17, 35) & "," EndIf ;Find lines with Step If StringLeft($FileArray[$LineNumber], 30) = " Current Process Step : Step" Then ;Now, just look for lines that have "Completed on" in them If StringInStr($FileArray[$LineNumber], "completed on ") Then ;Grab just the date off the line $textStageDate = _StringBetween($FileArray[$LineNumber], "completed on ", " by ") ;Grab just the Step Number and add it to the output line $StepNumber = StringRegExp($FileArray[$LineNumber], '(Step.\d+|Step\d)', 2) $OutputLine &= $StepNumber[0] & " - " ;Continue, even if output in malformed If Not IsArray($textStageDate) Then ContinueLoop ;Fix the date Fix_Date($textStageDate[0]) ;Add the step completed dates to the output line MsgBox(0,"Debug",$StepNumber[0]) If $StepNumber[0] = "Step1" Then $OutArray[1] = $StepNumber[0] & " - " & $textStageDate[0] EndIf If $StepNumber[0] = "Step2" Then $OutArray[2] = $StepNumber[0] & " - " & $textStageDate[0] EndIf If $StepNumber[0] = "Step3" Then $OutArray[3] = $StepNumber[0] & " - " & $textStageDate[0] EndIf If $StepNumber[0] = "Step4" Then $OutArray[4] = $StepNumber[0] & " - " & $textStageDate[0] EndIf If $StepNumber[0] = "Step5" Then $OutArray[5] = $StepNumber[0] & " - " & $textStageDate[0] EndIf If $StepNumber[0] = "Step6" Then $OutArray[6] = $StepNumber[0] & " - " & $textStageDate[0] EndIf If $StepNumber[0] = "Step7" Then $OutArray[7] = $StepNumber[0] & " - " & $textStageDate[0] EndIf If $StepNumber[0] = "Step8" Then $OutArray[8] = $StepNumber[0] & " - " & $textStageDate[0] EndIf If $StepNumber[0] = "Step9" Then $OutArray[9] = $StepNumber[0] & " - " & $textStageDate[0] EndIf If $StepNumber[0] = "Step 10" Then $OutArray[10] = $StepNumber[0]& " - " & $textStageDate[0] EndIf If $StepNumber[0] = "Step 11" Then $OutArray[11] = $StepNumber[0] & " - " & $textStageDate[0] EndIf If $StepNumber[0] = "Step 12" Then $OutArray[12] = $StepNumber[0] & " - " & $textStageDate[0] EndIf If $StepNumber[0] = "Step 13" Then $OutArray[13] = $StepNumber[0] & " - " & $textStageDate[0] EndIf If $StepNumber[0] = "Step 14" Then $OutArray[14] = $StepNumber[0] & " - " & $textStageDate[0] EndIf If $StepNumber[0] = "Step 15" Then $OutArray[15] = $StepNumber[0] & " - " & $textStageDate[0] EndIf _ArrayDisplay($OutArray) $OutputLine &= $textStageDate[0] & "," Else ;MsgBox(0, "Debug", "The line had a STEP, but not a COMPLETED STEP") EndIf EndIf Next FileWrite($OutputFile, $OutputLine & @CRLF) FileClose($InputFile) FileClose($OutputFile) SAMPLE REPORT expandcollapse popupServer Name : SERVER_01 Current Group : Completed Activity Log : 10/26/2010 7:29:14 AM v-bhowma Current Process Step : Planning completed on 10/26/2010 7:29:15 AM by v-bhowma 12/20/2010 11:16:26 AM reesebj Current Process Step : Step1 - Order Server canceled on 12/20/2010 11:16:26 AM by reesebj 10/26/2010 7:29:18 AM v-bhowma Current Process Step : Step1 - Order Server completed on 10/26/2010 7:29:19 AM by v-bhowma 10/26/2010 12:05:29 PM v-arunas Current Process Step : Step2 - Provide Network Facilities & Data completed on 10/26/2010 12:05:28 PM by v-arunas 10/28/2010 5:07:58 PM reesebj Current Process Step : Step3 - Facilities Prep completed on 10/28/2010 5:07:58 PM by reesebj 10/28/2010 5:08:01 PM reesebj Current Process Step : Step4 - Server Receipt completed on 10/28/2010 5:08:01 PM by reesebj 11/1/2010 11:56:30 AM v-bhowma Current Process Step : Step5 - Confirm Configuration completed on 11/1/2010 11:56:30 AM by v-bhowma 11/1/2010 11:56:35 AM v-bhowma Current Process Step : Step6 - Physical Install in Initial Location completed on 11/1/2010 11:56:34 AM by v-bhowma 11/1/2010 11:56:39 AM v-bhowma Current Process Step : Step7 - Stage Server and Configure SA completed on 11/1/2010 11:56:38 AM by v-bhowma 11/5/2010 9:15:21 PM reesebj Current Process Step : Step8 - Move Server to Production Floor or Ship to Location completed on 11/5/2010 9:15:21 PM by reesebj 11/15/2010 2:42:33 PM reesebj Current Process Step : Step 9 - Physical Install at Final Location completed on 11/15/2010 2:42:33 PM by reesebj 11/17/2010 7:40:37 AM v-bhowma Current Process Step : Step 10 - Configure SAN Disk completed on 11/17/2010 7:40:36 AM by v-bhowma 11/17/2010 7:40:40 AM v-bhowma Current Process Step : Step 11 - Configure Server for Intended Use completed on 11/17/2010 7:40:39 AM by v-bhowma 1/21/2011 5:41:20 PM v-chandd Current Process Step : Step 12 - Backups completed on 1/21/2011 5:41:19 PM by v-chandd 1/25/2011 3:13:40 PM v-isaacb Current Process Step : Step 13 - Monitoring completed on 1/25/2011 3:13:40 PM by v-isaacb 1/26/2011 7:08:58 AM v-bhowma Current Process Step : Step 14 - Security Scans & Remediation completed on 1/26/2011 7:08:57 AM by v-bhowma 1/27/2011 8:40:24 AM reesebj Final Turnover Approval for their group was given on 01/27/11 08:40:24 by reesebj 1/27/2011 5:41:33 PM morgarl Final Turnover Approval for their group was given on 01/27/11 17:41:33 by morgarl 2/2/2011 1:58:35 PM kenneac1 Final Turnover Approval for their group was given on 02/02/11 13:58:35 by kenneac1 2/4/2011 3:15:22 PM bokonb Final Turnover Approval for their group was given on 02/04/11 15:15:22 by bokonb 2/5/2011 6:02:55 PM v-giriu Final Turnover Approval for their group was given on 02/05/11 18:02:55 by v-giriu 2/8/2011 8:32:06 PM v-arunas Final Turnover Approval for their group was given on 02/08/11 20:32:06 by v-arunas 2/9/2011 6:21:45 AM v-bhowma Final Turnover Approval for their group was given on 02/09/11 06:21:45 by v-bhowma 2/15/2011 8:01:19 AM v-pandas1 Final Turnover Approval for their group was given on 02/15/11 08:01:19 by v-pandas1 2/15/2011 9:52:35 AM reesebj Current Process Step : Step 15 - QA completed on 2/15/2011 9:52:35 AM by reesebj Server Name : SERVER_02 Current Group : Completed Activity Log : 10/26/2010 7:32:26 AM v-bhowma Current Process Step : Planning completed on 10/26/2010 7:32:27 AM by v-bhowma 10/26/2010 7:32:30 AM v-bhowma Current Process Step : Step1 - Order Server completed on 10/26/2010 7:32:31 AM by v-bhowma 10/26/2010 12:05:35 PM v-arunas Current Process Step : Step2 - Provide Network Facilities & Data completed on 10/26/2010 12:05:35 PM by v-arunas 10/28/2010 5:08:05 PM reesebj Current Process Step : Step3 - Facilities Prep completed on 10/28/2010 5:08:05 PM by reesebj 10/28/2010 5:08:08 PM reesebj Current Process Step : Step4 - Server Receipt completed on 10/28/2010 5:08:08 PM by reesebj 11/1/2010 11:56:47 AM v-bhowma Current Process Step : Step5 - Confirm Configuration completed on 11/1/2010 11:56:47 AM by v-bhowma 11/1/2010 11:56:50 AM v-bhowma Current Process Step : Step6 - Physical Install in Initial Location completed on 11/1/2010 11:56:50 AM by v-bhowma 11/1/2010 11:56:54 AM v-bhowma Current Process Step : Step7 - Stage Server and Configure SA completed on 11/1/2010 11:56:53 AM by v-bhowma 11/5/2010 9:15:31 PM reesebj Current Process Step : Step8 - Move Server to Production Floor or Ship to Location completed on 11/5/2010 9:15:31 PM by reesebj 11/15/2010 2:42:37 PM reesebj Current Process Step : Step 9 - Physical Install at Final Location completed on 11/15/2010 2:42:37 PM by reesebj 11/17/2010 7:40:48 AM v-bhowma Current Process Step : Step 10 - Configure SAN Disk completed on 11/17/2010 7:40:47 AM by v-bhowma 11/17/2010 7:40:51 AM v-bhowma Current Process Step : Step 11 - Configure Server for Intended Use completed on 11/17/2010 7:40:50 AM by v-bhowma 1/21/2011 5:41:11 PM v-chandd Current Process Step : Step 12 - Backups completed on 1/21/2011 5:41:10 PM by v-chandd 1/25/2011 3:13:27 PM v-isaacb Current Process Step : Step 13 - Monitoring completed on 1/25/2011 3:13:27 PM by v-isaacb 1/26/2011 7:09:17 AM v-bhowma Current Process Step : Step 14 - Security Scans & Remediation completed on 1/26/2011 7:09:16 AM by v-bhowma 1/27/2011 8:40:30 AM reesebj Final Turnover Approval for their group was given on 01/27/11 08:40:30 by reesebj 1/27/2011 5:41:20 PM morgarl Final Turnover Approval for their group was given on 01/27/11 17:41:20 by morgarl 2/2/2011 1:58:24 PM kenneac1 Final Turnover Approval for their group was given on 02/02/11 13:58:24 by kenneac1 2/4/2011 3:15:13 PM bokonb Final Turnover Approval for their group was given on 02/04/11 15:15:13 by bokonb 2/5/2011 6:03:12 PM v-giriu Final Turnover Approval for their group was given on 02/05/11 18:03:12 by v-giriu 2/8/2011 8:32:27 PM v-arunas Final Turnover Approval for their group was given on 02/08/11 20:32:26 by v-arunas 2/9/2011 6:21:51 AM v-bhowma Final Turnover Approval for their group was given on 02/09/11 06:21:51 by v-bhowma 2/15/2011 8:01:32 AM v-pandas1 Final Turnover Approval for their group was given on 02/15/11 08:01:32 by v-pandas1 2/15/2011 9:52:40 AM reesebj Current Process Step : Step 15 - QA completed on 2/15/2011 9:52:39 AM by reesebj Server Name : SERVER_03 Current Group : Completed Activity Log : 10/26/2010 7:36:11 AM v-bhowma Current Process Step : Planning completed on 10/26/2010 7:36:12 AM by v-bhowma 10/26/2010 7:36:16 AM v-bhowma Current Process Step : Step1 - Order Server completed on 10/26/2010 7:36:16 AM by v-bhowma 10/26/2010 12:05:39 PM v-arunas Current Process Step : Step2 - Provide Network Facilities & Data completed on 10/26/2010 12:05:38 PM by v-arunas 10/28/2010 5:08:12 PM reesebj Current Process Step : Step3 - Facilities Prep completed on 10/28/2010 5:08:11 PM by reesebj 10/28/2010 5:08:14 PM reesebj Current Process Step : Step4 - Server Receipt completed on 10/28/2010 5:08:14 PM by reesebj 11/1/2010 11:57:02 AM v-bhowma Current Process Step : Step5 - Confirm Configuration completed on 11/1/2010 11:57:01 AM by v-bhowma 11/1/2010 11:57:05 AM v-bhowma Current Process Step : Step6 - Physical Install in Initial Location completed on 11/1/2010 11:57:05 AM by v-bhowma 11/1/2010 11:57:09 AM v-bhowma Current Process Step : Step7 - Stage Server and Configure SA completed on 11/1/2010 11:57:09 AM by v-bhowma 11/5/2010 9:15:36 PM reesebj Current Process Step : Step8 - Move Server to Production Floor or Ship to Location completed on 11/5/2010 9:15:36 PM by reesebj 11/15/2010 2:42:42 PM reesebj Current Process Step : Step 9 - Physical Install at Final Location completed on 11/15/2010 2:42:41 PM by reesebj 11/17/2010 7:40:56 AM v-bhowma Current Process Step : Step 10 - Configure SAN Disk completed on 11/17/2010 7:40:55 AM by v-bhowma 11/17/2010 7:41:00 AM v-bhowma Current Process Step : Step 11 - Configure Server for Intended Use completed on 11/17/2010 7:40:58 AM by v-bhowma 1/21/2011 5:41:01 PM v-chandd Current Process Step : Step 12 - Backups completed on 1/21/2011 5:41:00 PM by v-chandd 1/25/2011 3:13:14 PM v-isaacb Current Process Step : Step 13 - Monitoring completed on 1/25/2011 3:13:14 PM by v-isaacb 1/26/2011 7:09:32 AM v-bhowma Current Process Step : Step 14 - Security Scans & Remediation completed on 1/26/2011 7:09:31 AM by v-bhowma 1/27/2011 8:40:36 AM reesebj Final Turnover Approval for their group was given on 01/27/11 08:40:36 by reesebj 1/27/2011 5:41:07 PM morgarl Final Turnover Approval for their group was given on 01/27/11 17:41:06 by morgarl 2/2/2011 1:58:12 PM kenneac1 Final Turnover Approval for their group was given on 02/02/11 13:58:12 by kenneac1 2/4/2011 3:14:57 PM bokonb Final Turnover Approval for their group was given on 02/04/11 15:14:57 by bokonb 2/5/2011 6:03:25 PM v-giriu Final Turnover Approval for their group was given on 02/05/11 18:03:25 by v-giriu 2/8/2011 8:32:42 PM v-arunas Final Turnover Approval for their group was given on 02/08/11 20:32:42 by v-arunas 2/9/2011 8:52:29 AM v-bhowma Final Turnover Approval for their group was given on 02/09/11 08:52:29 by v-bhowma 2/15/2011 8:01:43 AM v-pandas1 Final Turnover Approval for their group was given on 02/15/11 08:01:43 by v-pandas1 2/15/2011 9:52:44 AM reesebj Current Process Step : Step 15 - QA completed on 2/15/2011 9:52:44 AM by reesebj Server Name : SERVER_04 Current Group : Completed Activity Log : 10/26/2010 7:39:55 AM v-bhowma Current Process Step : Planning completed on 10/26/2010 7:39:56 AM by v-bhowma 10/26/2010 7:40:00 AM v-bhowma Current Process Step : Step1 - Order Server completed on 10/26/2010 7:40:01 AM by v-bhowma 10/26/2010 12:05:47 PM v-arunas Current Process Step : Step2 - Provide Network Facilities & Data completed on 10/26/2010 12:05:47 PM by v-arunas 10/28/2010 5:08:18 PM reesebj Current Process Step : Step3 - Facilities Prep completed on 10/28/2010 5:08:18 PM by reesebj 10/28/2010 5:08:21 PM reesebj Current Process Step : Step4 - Server Receipt completed on 10/28/2010 5:08:20 PM by reesebj 11/1/2010 11:57:15 AM v-bhowma Current Process Step : Step5 - Confirm Configuration completed on 11/1/2010 11:57:15 AM by v-bhowma 11/1/2010 11:57:19 AM v-bhowma Current Process Step : Step6 - Physical Install in Initial Location completed on 11/1/2010 11:57:18 AM by v-bhowma 11/1/2010 11:57:22 AM v-bhowma Current Process Step : Step7 - Stage Server and Configure SA completed on 11/1/2010 11:57:22 AM by v-bhowma 11/5/2010 9:15:41 PM reesebj Current Process Step : Step8 - Move Server to Production Floor or Ship to Location completed on 11/5/2010 9:15:41 PM by reesebj 11/15/2010 2:42:46 PM reesebj Current Process Step : Step 9 - Physical Install at Final Location completed on 11/15/2010 2:42:46 PM by reesebj 11/17/2010 7:41:06 AM v-bhowma Current Process Step : Step 10 - Configure SAN Disk completed on 11/17/2010 7:41:05 AM by v-bhowma 11/17/2010 7:41:09 AM v-bhowma Current Process Step : Step 11 - Configure Server for Intended Use completed on 11/17/2010 7:41:08 AM by v-bhowma 1/21/2011 5:40:49 PM v-chandd Current Process Step : Step 12 - Backups completed on 1/21/2011 5:40:48 PM by v-chandd 1/25/2011 3:13:00 PM v-isaacb Current Process Step : Step 13 - Monitoring completed on 1/25/2011 3:13:00 PM by v-isaacb 1/26/2011 7:09:49 AM v-bhowma Current Process Step : Step 14 - Security Scans & Remediation completed on 1/26/2011 7:09:48 AM by v-bhowma 1/27/2011 8:40:41 AM reesebj Final Turnover Approval for their group was given on 01/27/11 08:40:41 by reesebj 1/27/2011 5:40:53 PM morgarl Final Turnover Approval for their group was given on 01/27/11 17:40:53 by morgarl 2/2/2011 1:57:53 PM kenneac1 Final Turnover Approval for their group was given on 02/02/11 13:57:52 by kenneac1 2/4/2011 3:14:45 PM bokonb Final Turnover Approval for their group was given on 02/04/11 15:14:45 by bokonb 2/5/2011 6:03:37 PM v-giriu Final Turnover Approval for their group was given on 02/05/11 18:03:37 by v-giriu 2/8/2011 8:33:05 PM v-arunas Final Turnover Approval for their group was given on 02/08/11 20:33:05 by v-arunas 2/9/2011 8:52:39 AM v-bhowma Final Turnover Approval for their group was given on 02/09/11 08:52:39 by v-bhowma 2/15/2011 8:01:56 AM v-pandas1 Final Turnover Approval for their group was given on 02/15/11 08:01:56 by v-pandas1 2/15/2011 9:52:48 AM reesebj Current Process Step : Step 15 - QA completed on 2/15/2011 9:52:48 AM by reesebj Server Name : SERVER_05 Current Group : Process Canceled Activity Log : 10/27/2010 2:22:29 PM v-doriob European Mail Exchange 2007 Cluster Server 1 10/27/2010 2:25:41 PM v-doriob Current Process Step : Planning completed on 10/27/2010 2:25:41 PM by v-doriob 11/8/2010 2:27:50 PM v-doriob Current Process Step : Step1 - Order Server completed on 11/8/2010 2:27:50 PM by v-doriob 11/15/2010 11:16:10 AM v-arunas Current Process Step : Step2 - Provide Network Facilities & Data completed on 11/15/2010 11:16:10 AM by v-arunas 11/15/2010 2:40:32 PM reesebj Current Process Step : Step3 - Facilities Prep completed on 11/15/2010 2:40:32 PM by reesebj 11/15/2010 2:40:36 PM reesebj Current Process Step : Step4 - Server Receipt completed on 11/15/2010 2:40:36 PM by reesebj 11/17/2010 7:41:17 AM v-bhowma Current Process Step : Step5 - Confirm Configuration completed on 11/17/2010 7:41:16 AM by v-bhowma 11/22/2010 11:49:57 AM reesebj Current Process Step : Step6 - Physical Install in Initial Location canceled on 11/22/2010 11:49:57 AM by reesebj Any help would be appreciated. Thank you. Edited August 1, 2011 by lhk69
sleepydvdr Posted August 1, 2011 Posted August 1, 2011 The code below DOES NOT work correctly, but I think it is on the right track. I don't have any more time to look at this today. Maybe tomorrow. Most of what I did was near the end. One thing was to get rid of the 15 separate steps and put it in a loop. I was last working on the duplicating your 15 step section so that if it does not read "completed on" the default to "cancelled on" and write dummy lines to it. That is the part I haven't got working yet. expandcollapse popup#include <File.au3> #include <array.au3> #include <String.au3> #include <Date.au3> Global $FileArray, $OutputLine, $textStageDate[1], $OutArray[16] Global $InputFile = "report.rep" Func Fix_Date_1($input) ;Replace comma with space Local $temp0 = StringReplace($input, ",", "") ;Remove the DAY If StringLeft($temp0, 3) = "Mon" Then Local $temp1 = StringReplace($temp0, "Monday ", "") EndIf If StringLeft($temp0, 3) = "Tue" Then Local $temp1 = StringReplace($temp0, "Tuesday ", "") EndIf If StringLeft($temp0, 3) = "Wed" Then Local $temp1 = StringReplace($temp0, "Wednesday ", "") EndIf If StringLeft($temp0, 3) = "Thu" Then Local $temp1 = StringReplace($temp0, "Thursday ", "") EndIf If StringLeft($temp0, 3) = "Fri" Then Local $temp1 = StringReplace($temp0, "Friday ", "") EndIf If StringLeft($temp0, 3) = "Sat" Then Local $temp1 = StringReplace($temp0, "Saturday ", "") EndIf If StringLeft($temp0, 3) = "Sun" Then Local $temp1 = StringReplace($temp0, "Sunday ", "") EndIf ;Split up result into array Local $temp = StringSplit($temp1, " ") ;Convert Month into a numeric value Local $month = StringSplit("Jan,Feb,Mar,Apr,May,June,July,Aug,Sept,Oct,Nov,Dec", ",") For $x = 1 To 12 If StringInStr($temp[1], $month[$x]) Then Return $x & "/" & $temp[2] & "/" & $temp[3] & " " & $temp[4] & " " & $temp[5] Next Return SetError(1, 0, -1) EndFunc ;==>Fix_Date_1 Func Fix_Date_2($input) ;Replace comma with space Local $temp0 = StringReplace($input, ".", " ") ;Split up result into array Local $temp = StringSplit($temp0, " ") ;_ArrayDisplay($temp) Return $temp[2] & "/" & $temp[3] & "/" & $temp[1] & " " & $temp[5] Return SetError(1, 0, -1) EndFunc Func Fix_Date($input) If StringLeft($input, 5) = "2011." Then $FixedDate = Fix_Date_2($input) $textStageDate[0] = $FixedDate EndIf If StringLeft($input, 3) = "Mon" Then $FixedDate = Fix_Date_1($input) $textStageDate[0] = $FixedDate EndIf If StringLeft($input, 3) = "Tue" Then $FixedDate = Fix_Date_1($input) $textStageDate[0] = $FixedDate EndIf If StringLeft($input, 3) = "Wed" Then $FixedDate = Fix_Date_1($input) $textStageDate[0] = $FixedDate EndIf If StringLeft($input, 3) = "Thu" Then $FixedDate = Fix_Date_1($input) $textStageDate[0] = $FixedDate EndIf If StringLeft($input, 3) = "Fri" Then $FixedDate = Fix_Date_1($input) $textStageDate[0] = $FixedDate EndIf If StringLeft($input, 3) = "Sat" Then $FixedDate = Fix_Date_1($input) $textStageDate[0] = $FixedDate EndIf If StringLeft($input, 3) = "Sun" Then $FixedDate = Fix_Date_1($input) $textStageDate[0] = $FixedDate EndIf EndFunc If Not _FileReadToArray($InputFile, $FileArray) Then MsgBox(0, "Error", "Unable to open Input file.") Exit EndIf $OutputFile = FileOpen("results.csv", 10) If $OutputFile = -1 Then MsgBox(0, "Error", "Unable to open Output file.") Exit EndIf For $LineNumber = 1 To $FileArray[0] ; Read each line ;Find a line with "Server Name" on it and just return the SERVER NAME If StringLeft($FileArray[$LineNumber], 14) = "Server Name : " Then FileWrite($OutputFile, $OutputLine & @CRLF) $OutputLine = StringMid($FileArray[$LineNumber], 15, 15) & "," EndIf ;Then find a line with "Current Group" on it and just return the GROUP NAME and add it to the output line If StringLeft($FileArray[$LineNumber], 16) = "Current Group : " Then $OutputLine &= StringMid($FileArray[$LineNumber], 17, 35) & "," EndIf ;Find lines with Step If StringLeft($FileArray[$LineNumber], 30) = " Current Process Step : Step" Then ;Now, just look for lines that have "Completed on" in them If StringInStr($FileArray[$LineNumber], "completed on ") Then ;Grab just the date off the line $textStageDate = _StringBetween($FileArray[$LineNumber], "completed on ", " by ") ;Grab just the Step Number and add it to the output line $StepNumber = StringRegExp($FileArray[$LineNumber], '(Step.\d+|Step\d)', 2) $OutputLine &= $StepNumber[0] & " - " ;Continue, even if output in malformed If Not IsArray($textStageDate) Then ContinueLoop ;Fix the date Fix_Date($textStageDate[0]) ;Add the step completed dates to the output line ;MsgBox(0,"Debug",$StepNumber[0]) For $i = 1 to 15 Step 1 If $StepNumber[0] = "Step" & $i Then $OutArray[$i] = $StepNumber[0] & " - " & $textStageDate[0] EndIf Next ;_ArrayDisplay($OutArray) $OutputLine &= $textStageDate[0] & "," Else If $textStageDate = _StringBetween($FileArray[$LineNumber], "canceled on ", " by ") Then $StepNumber = StringRegExp($FileArray[$LineNumber], '(Step.\d+|Step\d)', 2) $OutputLine &= $StepNumber[0] & " - " For $i = 1 to 15 Step 1 $OutArray[$i] = $StepNumber[0] & " = NO_VALUE" & $textStageDate[0] Next $OutputLine &= $textStageDate[0] & "," EndIf EndIf EndIf Next FileWrite($OutputFile, $OutputLine & @CRLF) FileClose($InputFile) FileClose($OutputFile) #include <ByteMe.au3>
hannes08 Posted August 1, 2011 Posted August 1, 2011 Hi lhk69, I tested the below code, but is hasn't got any error-checking. Anyway I din't understand what you were trying to achieve with your Fix_date functions. expandcollapse popup#include <File.au3> #include <array.au3> #include <String.au3> Global $FileArray, $OutputLine, $textStageDate[1], $OutArray[16] Global $InputFile = @DesktopDir & "\report.txt" If Not _FileReadToArray($InputFile, $FileArray) Then MsgBox(0, "Error", "Unable to open Input file.") Exit EndIf $OutputFile = FileOpen(@DesktopDir & "\results.csv", 10) If $OutputFile = -1 Then MsgBox(0, "Error", "Unable to open Output file.") Exit EndIf Dim $a_line[18] $a_line[0] = 17 For $LineNumber = 1 To $FileArray[0] ; Read each line ;Find a line with "Server Name" on it and just return the SERVER NAME If StringLeft($FileArray[$LineNumber], 14) = "Server Name : " Then If $LineNumber > 1 Then $a_line = _flusharray($a_line, $OutputFile) $a_line[1] = StringMid($FileArray[$LineNumber], 15, 15) EndIf ;Then find a line with "Current Group" on it and just return the GROUP NAME and add it to the output line If StringLeft($FileArray[$LineNumber], 16) = "Current Group : " Then $a_line[2] = StringMid($FileArray[$LineNumber], 17, 35) EndIf ;Find lines with Step $a_step = StringRegExp($FileArray[$LineNumber], '(Step.\d+|Step\d)', 2) If @error = 0 And IsArray($a_step) Then $i_step =StringStripWS(StringReplace($a_step[0], "Step",""), 3) $a_time = _StringBetween($FileArray[$LineNumber], "ed on ", " by ") $s_time = $a_time[0] $a_line[2 + $i_step] = $a_step[0] & " - " & $s_time EndIf Next _flusharray($a_line, $OutputFile) FileClose($InputFile) FileClose($OutputFile) Func _flusharray($array, $fh) _ArrayDisplay($array) FileWriteLine($fh, _ArrayToString($array, ",", 1)) Dim $line[18] $line[0] = 17 Return $line EndFunc Basically I create an empty array for each dataset, and fill the cells in the arry with the according data, e.g. Cell 1 is the Servername, Cell 2 is the Current Status, Cell 3 - 17 are the current steps. I am sure that there is a better solution on how to get the step-number that using your regex and replacing "Step" with ""... Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]
lhk69 Posted August 2, 2011 Author Posted August 2, 2011 Hi. Check this out. I "THINK" I got it working. I know its really bad code. But, Im still new and not a very good programmer. Hannes, the fix_date stuff is because most dates are in the form MM/DD/YYYY HH:MM:SS. SOME are like; Wednesday, July 31st, 2011, or 2011.12.10 The functions are to fix them. Im sure there is a better way. I did it the only way I could figure it out. Sleepy. I think I will definitely be using your loop. I know, my code is very elementary. Sometimes, I just dont think. You are right about the loop. Thank you both for your input. PLEASE tell me what you think or any way I can improve this. expandcollapse popup#include <File.au3> #include <array.au3> #include <String.au3> #include <Date.au3> Global $FileArray, $OutputLine, $textStageDate[1], $OutArray[16] Global $InputFile = "c:\documents and settings\v-kleinl\desktop\report.rep" Func Fix_Date_1($input) ;Replace comma with space Local $temp0 = StringReplace($input, ",", "") ;Remove the DAY If StringLeft($temp0, 3) = "Mon" Then Local $temp1 = StringReplace($temp0, "Monday ", "") EndIf If StringLeft($temp0, 3) = "Tue" Then Local $temp1 = StringReplace($temp0, "Tuesday ", "") EndIf If StringLeft($temp0, 3) = "Wed" Then Local $temp1 = StringReplace($temp0, "Wednesday ", "") EndIf If StringLeft($temp0, 3) = "Thu" Then Local $temp1 = StringReplace($temp0, "Thursday ", "") EndIf If StringLeft($temp0, 3) = "Fri" Then Local $temp1 = StringReplace($temp0, "Friday ", "") EndIf If StringLeft($temp0, 3) = "Sat" Then Local $temp1 = StringReplace($temp0, "Saturday ", "") EndIf If StringLeft($temp0, 3) = "Sun" Then Local $temp1 = StringReplace($temp0, "Sunday ", "") EndIf ;Split up result into array Local $temp = StringSplit($temp1, " ") ;Convert Month into a numeric value Local $month = StringSplit("Jan,Feb,Mar,Apr,May,June,July,Aug,Sept,Oct,Nov,Dec", ",") For $x = 1 To 12 If StringInStr($temp[1], $month[$x]) Then Return $x & "/" & $temp[2] & "/" & $temp[3] & " " & $temp[4] & " " & $temp[5] Next Return SetError(1, 0, -1) EndFunc ;==>Fix_Date_1 Func Fix_Date_2($input) ;Replace comma with space Local $temp0 = StringReplace($input, ".", " ") ;Split up result into array Local $temp = StringSplit($temp0, " ") ;_ArrayDisplay($temp) Return $temp[2] & "/" & $temp[3] & "/" & $temp[1] & " " & $temp[5] Return SetError(1, 0, -1) EndFunc Func Fix_Date($input) If StringLeft($input, 5) = "2011." Then $FixedDate = Fix_Date_2($input) $textStageDate[0] = $FixedDate EndIf If StringLeft($input, 3) = "Mon" Then $FixedDate = Fix_Date_1($input) $textStageDate[0] = $FixedDate EndIf If StringLeft($input, 3) = "Tue" Then $FixedDate = Fix_Date_1($input) $textStageDate[0] = $FixedDate EndIf If StringLeft($input, 3) = "Wed" Then $FixedDate = Fix_Date_1($input) $textStageDate[0] = $FixedDate EndIf If StringLeft($input, 3) = "Thu" Then $FixedDate = Fix_Date_1($input) $textStageDate[0] = $FixedDate EndIf If StringLeft($input, 3) = "Fri" Then $FixedDate = Fix_Date_1($input) $textStageDate[0] = $FixedDate EndIf If StringLeft($input, 3) = "Sat" Then $FixedDate = Fix_Date_1($input) $textStageDate[0] = $FixedDate EndIf If StringLeft($input, 3) = "Sun" Then $FixedDate = Fix_Date_1($input) $textStageDate[0] = $FixedDate EndIf EndFunc If Not _FileReadToArray($InputFile, $FileArray) Then MsgBox(0, "Error", "Unable to open Input file.") Exit EndIf $OutputFile = FileOpen("c:\documents and settings\v-kleinl\desktop\results.csv", 10) If $OutputFile = -1 Then MsgBox(0, "Error", "Unable to open Output file.") Exit EndIf For $LineNumber = 1 To $FileArray[0] ; Read each line ;Find a line with "Server Name" on it and just return the SERVER NAME If StringLeft($FileArray[$LineNumber], 14) = "Server Name : " Then For $i = 1 to 15 $OutputLine = $OutputLine & $OutArray[$i] & "," Next $OutArray[1] = "" $OutArray[2] = "" $OutArray[3] = "" $OutArray[4] = "" $OutArray[5] = "" $OutArray[6] = "" $OutArray[7] = "" $OutArray[8] = "" $OutArray[9] = "" $OutArray[10] = "" $OutArray[11] = "" $OutArray[12] = "" $OutArray[13] = "" $OutArray[14] = "" $OutArray[15] = "" FileWrite($OutputFile, $OutputLine & @CRLF) $OutputLine = StringMid($FileArray[$LineNumber], 15, 15) & "," $ServerName = StringMid($FileArray[$LineNumber], 15, 15) EndIf ;Then find a line with "Current Group" on it and just return the GROUP NAME and add it to the output line If StringLeft($FileArray[$LineNumber], 16) = "Current Group : " Then $OutputLine &= StringMid($FileArray[$LineNumber], 17, 35) & "," $CurrentGroup = StringMid($FileArray[$LineNumber], 17, 35) EndIf ;Find lines with Step If StringLeft($FileArray[$LineNumber], 30) = " Current Process Step : Step" Then ;Now, just look for lines that have "completed on" or "canceled on" in them ;MsgBox(0,"Line to look at",$FileArray[$LineNumber]) If StringInStr($FileArray[$LineNumber], "completed on ") or StringInStr($FileArray[$LineNumber], "canceled on ") Then $Answer = StringInStr($FileArray[$LineNumber], "completed on ") or StringInStr($FileArray[$LineNumber], "canceled on ") ;MsgBox(0,"Found COMPLETE or CANCELED",$Answer) $AnswerCOMPLETE = StringInStr($FileArray[$LineNumber], "completed on ") ;MsgBox(0,"Complete???",$AnswerCOMPLETE) $AnswerCANCELED = StringInStr($FileArray[$LineNumber], "canceled on ") ;MsgBox(0,"Canceled???",$AnswerCANCELED) If $AnswerCOMPLETE > 0 Then ;Grab just the completed date off the line $textStageDate = _StringBetween($FileArray[$LineNumber], "completed on ", " by ") ;msgbox(0,"Line with completed", "Line with completed on " & $textStageDate ) Else ;Grab just the canceled date off the line $textStageDate = _StringBetween($FileArray[$LineNumber], "canceled on ", " by ") ;msgbox(0,"Line with canceled", "Line with canceled on" & $textStageDate ) EndIf ;Grab just the Step Number and add it to the output line $StepNumber = StringRegExp($FileArray[$LineNumber], '(Step.\d+|Step\d)', 2) ;Continue, even if output in malformed If Not IsArray($textStageDate) Then ContinueLoop ;Fix the date Fix_Date($textStageDate[0]) ;Add the step completed dates to the output line ;MsgBox(0,"Debug",$StepNumber[0]) $OutArray[0] = $ServerName & " " & $CurrentGroup If $StepNumber[0] = "Step1" Then $OutArray[1] = $StepNumber[0] & " - " & $textStageDate[0] EndIf If $StepNumber[0] = "Step2" Then $OutArray[2] = $StepNumber[0] & " - " & $textStageDate[0] EndIf If $StepNumber[0] = "Step3" Then $OutArray[3] = $StepNumber[0] & " - " & $textStageDate[0] EndIf If $StepNumber[0] = "Step4" Then $OutArray[4] = $StepNumber[0] & " - " & $textStageDate[0] EndIf If $StepNumber[0] = "Step5" Then $OutArray[5] = $StepNumber[0] & " - " & $textStageDate[0] EndIf If $StepNumber[0] = "Step6" Then $OutArray[6] = $StepNumber[0] & " - " & $textStageDate[0] EndIf If $StepNumber[0] = "Step7" Then $OutArray[7] = $StepNumber[0] & " - " & $textStageDate[0] EndIf If $StepNumber[0] = "Step8" Then $OutArray[8] = $StepNumber[0] & " - " & $textStageDate[0] EndIf If $StepNumber[0] = "Step 9" Then $OutArray[9] = $StepNumber[0] & " - " & $textStageDate[0] EndIf If $StepNumber[0] = "Step 10" Then $OutArray[10] = $StepNumber[0]& " - " & $textStageDate[0] EndIf If $StepNumber[0] = "Step 11" Then $OutArray[11] = $StepNumber[0] & " - " & $textStageDate[0] EndIf If $StepNumber[0] = "Step 12" Then $OutArray[12] = $StepNumber[0] & " - " & $textStageDate[0] EndIf If $StepNumber[0] = "Step 13" Then $OutArray[13] = $StepNumber[0] & " - " & $textStageDate[0] EndIf If $StepNumber[0] = "Step 14" Then $OutArray[14] = $StepNumber[0] & " - " & $textStageDate[0] EndIf If $StepNumber[0] = "Step 15" Then $OutArray[15] = $StepNumber[0] & " - " & $textStageDate[0] EndIf ;_ArrayDisplay($OutArray) ;$OutputLine &= $textStageDate[0] & "," Else ;MsgBox(0, "Debug", "The line had a STEP, but not a COMPLETED STEP") EndIf EndIf Next For $i = 1 to 15 $OutputLine = $OutputLine & $OutArray[$i] & "," Next FileWrite($OutputFile, $OutputLine & @CRLF) FileClose($InputFile) FileClose($OutputFile)
lhk69 Posted August 3, 2011 Author Posted August 3, 2011 Hi guys. Please check out my current code. I learned a lot from you two. Thank you again and PLEASE let me know if there is any way I can improve this. I know I have much to learn. expandcollapse popup#include <File.au3> #include <array.au3> #include <String.au3> Global $FileArray, $OutputLine, $textStageDate[1], $OutArray[16] Global $InputFile = @DesktopDir & "\report.rep" If Not _FileReadToArray($InputFile, $FileArray) Then MsgBox(0, "Error", "Unable to open Input file.") Exit EndIf $OutputFile = FileOpen(@DesktopDir & "\results.csv", 10) If $OutputFile = -1 Then MsgBox(0, "Error", "Unable to open Output file.") Exit EndIf Dim $array_line[18] $array_line[0] = 17 For $LineNumber = 1 To $FileArray[0] ; Read each line ;Find a line with "Server Name" on it and just return the SERVER NAME If StringLeft($FileArray[$LineNumber], 14) = "Server Name : " Then If $LineNumber > 1 Then $array_line = _flusharray($array_line, $OutputFile) $array_line[1] = StringMid($FileArray[$LineNumber], 15, 15) EndIf ;Then find a line with "Current Group" on it and just return the GROUP NAME and add it to the output line If StringLeft($FileArray[$LineNumber], 16) = "Current Group : " Then $array_line[2] = StringMid($FileArray[$LineNumber], 17, 35) EndIf ;Find lines with Step If StringLeft($FileArray[$LineNumber], 30) = " Current Process Step : Step" Then If StringInStr($FileArray[$LineNumber], "completed on ") Or StringInStr($FileArray[$LineNumber], "canceled on ") Then $array_step = StringRegExp($FileArray[$LineNumber], '(Step.\d+|Step\d)', 2) If @error = 0 And IsArray($array_step) Then $i_step = StringStripWS(StringReplace($array_step[0], "Step", ""), 3) $array_time = _StringBetween($FileArray[$LineNumber], "ed on ", " by ") $s_time = $array_time[0] Fix_Date($s_time) $array_line[2 + $i_step] = $array_step[0] & " - " & $s_time EndIf EndIf EndIf Next _flusharray($array_line, $OutputFile) FileClose($InputFile) FileClose($OutputFile) Func _flusharray($array, $fh) ;_ArrayDisplay($array) FileWriteLine($fh, _ArrayToString($array, ",", 1)) Dim $line[18] $line[0] = 17 Return $line EndFunc Func Fix_Date_1($input) ;Replace comma with space Local $temp0 = StringReplace($input, ",", "") ;Remove the DAY If StringLeft($temp0, 3) = "Mon" Then Local $temp1 = StringReplace($temp0, "Monday ", "") EndIf If StringLeft($temp0, 3) = "Tue" Then Local $temp1 = StringReplace($temp0, "Tuesday ", "") EndIf If StringLeft($temp0, 3) = "Wed" Then Local $temp1 = StringReplace($temp0, "Wednesday ", "") EndIf If StringLeft($temp0, 3) = "Thu" Then Local $temp1 = StringReplace($temp0, "Thursday ", "") EndIf If StringLeft($temp0, 3) = "Fri" Then Local $temp1 = StringReplace($temp0, "Friday ", "") EndIf If StringLeft($temp0, 3) = "Sat" Then Local $temp1 = StringReplace($temp0, "Saturday ", "") EndIf If StringLeft($temp0, 3) = "Sun" Then Local $temp1 = StringReplace($temp0, "Sunday ", "") EndIf ;Split up result into array Local $temp = StringSplit($temp1, " ") ;Convert Month into a numeric value Local $month = StringSplit("Jan,Feb,Mar,Apr,May,June,July,Aug,Sept,Oct,Nov,Dec", ",") For $x = 1 To 12 If StringInStr($temp[1], $month[$x]) Then Return $x & "/" & $temp[2] & "/" & $temp[3] & " " & $temp[4] & " " & $temp[5] Next Return SetError(1, 0, -1) EndFunc Func Fix_Date_2($input) ;Replace comma with space Local $temp0 = StringReplace($input, ".", " ") ;Split up result into array Local $temp = StringSplit($temp0, " ") ;_ArrayDisplay($temp) Return $temp[2] & "/" & $temp[3] & "/" & $temp[1] & " " & $temp[5] Return SetError(1, 0, -1) EndFunc Func Fix_Date($input) If StringLeft($input, 5) = "2011." Then $FixedDate = Fix_Date_2($input) $s_time = $FixedDate EndIf If StringLeft($input, 3) = "Mon" Then $FixedDate = Fix_Date_1($input) $s_time = $FixedDate EndIf If StringLeft($input, 3) = "Tue" Then $FixedDate = Fix_Date_1($input) $s_time = $FixedDate EndIf If StringLeft($input, 3) = "Wed" Then $FixedDate = Fix_Date_1($input) $s_time = $FixedDate EndIf If StringLeft($input, 3) = "Thu" Then $FixedDate = Fix_Date_1($input) $s_time = $FixedDate EndIf If StringLeft($input, 3) = "Fri" Then $FixedDate = Fix_Date_1($input) $s_time = $FixedDate EndIf If StringLeft($input, 3) = "Sat" Then $FixedDate = Fix_Date_1($input) $s_time = $FixedDate EndIf If StringLeft($input, 3) = "Sun" Then $FixedDate = Fix_Date_1($input) $s_time = $FixedDate EndIf EndFunc
hannes08 Posted August 3, 2011 Posted August 3, 2011 ;Add on top of your script: Global $a_days[8] = [7, "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] ;replace the 7 if statements in Function Fix_date() with: If _ArraySearch($a_days, StringLeft($input, 3), 1, $a_days[0], 0, 1) Then $FixedDate = Fix_Date_1($input) $s_time = $FixedDate EndIf ;replace the 7 if statements in Function Fix_date_1() with: $temp1 = $temp0 For $i = 1 To $a_days[0] $temp1 = StringReplace($temp1, $a_days[$i] & " ", "") Next This will simplyfy your script and save you code you don't need to type. Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]
lhk69 Posted August 3, 2011 Author Posted August 3, 2011 Hannes. Thanks for the suggestions. I used them both. Now, the fix_date function returns a "-1" when the fix_date_1 is run. It works fine with all my IF statements. The replacement in the Fix_date_1 replacement of all the IF's with loop is fine. What did I miss? expandcollapse popup#include <File.au3> #include <array.au3> #include <String.au3> Global $FileArray, $OutputLine, $textStageDate[1], $OutArray[16] Global $InputFile = @DesktopDir & "\report.rep" ;Add on top of your script: Global $a_days[8] = [7, "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] ;=TEXT(ROUNDDOWN((D2-C2),0),"0")&"days"&" "&TEXT(MOD((D2-C2)*1440/60,24),"00")& "hours"&" "&TEXT(MOD((D2-C2)*1440,60),"00")& "min" If Not _FileReadToArray($InputFile, $FileArray) Then MsgBox(0, "Error", "Unable to open Input file.") Exit EndIf $OutputFile = FileOpen(@DesktopDir & "\results.csv", 10) If $OutputFile = -1 Then MsgBox(0, "Error", "Unable to open Output file.") Exit EndIf Dim $array_line[18] $array_line[0] = 17 For $LineNumber = 1 To $FileArray[0] ; Read each line ;Find a line with "Server Name" on it and just return the SERVER NAME If StringLeft($FileArray[$LineNumber], 14) = "Server Name : " Then If $LineNumber > 1 Then $array_line = _flusharray($array_line, $OutputFile) $array_line[1] = StringMid($FileArray[$LineNumber], 15, 15) EndIf ;Then find a line with "Current Group" on it and just return the GROUP NAME and add it to the output line If StringLeft($FileArray[$LineNumber], 16) = "Current Group : " Then $array_line[2] = StringMid($FileArray[$LineNumber], 17, 35) EndIf ;Find lines with Step If StringLeft($FileArray[$LineNumber], 30) = " Current Process Step : Step" Then If StringInStr($FileArray[$LineNumber], "completed on ") Or StringInStr($FileArray[$LineNumber], "canceled on ") Then $array_step = StringRegExp($FileArray[$LineNumber], '(Step.\d+|Step\d)', 2) If @error = 0 And IsArray($array_step) Then $i_step = StringStripWS(StringReplace($array_step[0], "Step", ""), 3) $array_time = _StringBetween($FileArray[$LineNumber], "ed on ", " by ") $s_time = $array_time[0] ;MsgBox(0,"Time Debug",$s_time) Fix_Date($s_time) $array_line[2 + $i_step] = $array_step[0] & " - " & $s_time $array_line[2 + $i_step] = $s_time EndIf EndIf EndIf Next _flusharray($array_line, $OutputFile) FileClose($InputFile) FileClose($OutputFile) Func _flusharray($array, $fh) ;_ArrayDisplay($array) FileWriteLine($fh, _ArrayToString($array, ",", 1)) Dim $line[18] $line[0] = 17 Return $line EndFunc Func Fix_Date_1($input) ;Replace comma with space Local $temp0 = StringReplace($input, ",", "") ;Remove the DAY $temp1 = $temp0 For $i = 1 To $a_days[0] $temp1 = StringReplace($temp1, $a_days[$i] & " ", "") Next ;Split up result into array Local $temp = StringSplit($temp1, " ") ;Convert Month into a numeric value Local $month = StringSplit("Jan,Feb,Mar,Apr,May,June,July,Aug,Sept,Oct,Nov,Dec", ",") For $x = 1 To 12 If StringInStr($temp[1], $month[$x]) Then Return $x & "/" & $temp[2] & "/" & $temp[3] & " " & $temp[4] & " " & $temp[5] Next Return SetError(1, 0, -1) EndFunc Func Fix_Date_2($input) ;Replace comma with space Local $temp0 = StringReplace($input, ".", " ") ;Split up result into array Local $temp = StringSplit($temp0, " ") ;_ArrayDisplay($temp) Return $temp[2] & "/" & $temp[3] & "/" & $temp[1] & " " & $temp[5] Return SetError(1, 0, -1) EndFunc Func Fix_Date($input) If StringLeft($input, 5) = "2011." Then $FixedDate = Fix_Date_2($input) $s_time = $FixedDate EndIf If _ArraySearch($a_days, StringLeft($input, 3), 1, $a_days[0], 0, 1) Then msgbox(0,"Debug - before fixdate",$input) $FixedDate = Fix_Date_1($input) msgbox(0,"Debug - after fixdate",$FixedDate) $s_time = $FixedDate EndIf EndFunc
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