gcue Posted February 20, 2022 Posted February 20, 2022 hello all i am dealing with multiple large log files and using _FileReadToArray to get the log data into arrays (with a comma delimiter). sometimes there are more commas than I am expecting so more columns are created in the array which is causing me issues. the number of extra columns varies. I would only like to keep the first 2 columns and merge any extra columns to column 2. i found this from Malkey but it specifies exact column numbers to merge and in my case the column quantities vary. any help is significantly appreciated!
ad777 Posted February 20, 2022 Posted February 20, 2022 (edited) @gcue Can you post your script,so i can help??? Edited February 20, 2022 by ad777 none
gcue Posted February 20, 2022 Author Posted February 20, 2022 (edited) might be hard to give you the data / log file but this is essentially what im trying to do... Example Dataset 1 - just has 2 columns at which the function Keep2Columns would do nothing Example Dataset 2 - would merge columns 3-5 with column 2 Example Dataset 3 - would merge columns 3-7 with column 2 Basically stuck where I'm at Many thanks in advance! expandcollapse popup;Example Dataset 1 Local $log_array[10][2] For $x = 0 To UBound($log_array) - 1 For $y = 0 To UBound($log_array, 2) - 1 $log_array[$x][$y] = $x & "-" & $y Next Next _ArrayDisplay($log_array) $log_array = Keep2Columns($log_array) ;Example Dataset 2 Local $log_array[10][5] For $x = 0 To UBound($log_array) - 1 For $y = 0 To UBound($log_array, 2) - 1 $log_array[$x][$y] = $x & "-" & $y Next Next _ArrayDisplay($log_array) $log_array = Keep2Columns($log_array) _ArrayDisplay($log_array) ;Example Dataset 3 Local $log_array[10][7] For $x = 0 To UBound($log_array) - 1 For $y = 0 To UBound($log_array, 2) - 1 $log_array[$x][$y] = $x & "-" & $y Next Next _ArrayDisplay($log_array) $log_array = Keep2Columns($log_array) _ArrayDisplay($log_array) Func Keep2Columns($array) $columns_to_merge = UBound($array, 2) - 2 If UBound($array, 2) > 2 Then For $x = 0 To UBound($array) - 1 For $y = 0 To $columns_to_merge - 1 Next Next EndIf Return $array EndFunc ;==>Keep2Columns Edited February 20, 2022 by gcue
Moderators Melba23 Posted February 20, 2022 Moderators Posted February 20, 2022 gcue, This is how I would do it: expandcollapse popup#include <Array.au3> ; Create arrays with different numbers of columns For $i = 3 To 7 Global $aInitialArray[7][$i] For $j = 0 To 6 For $k = 0 To $i - 1 $aInitialArray[$j][$k] = $j & "-" & $k Next Next _ArrayDisplay($aInitialArray, "Initial", Default, 8) $aNewArray = _3ColArray($aInitialArray) _ArrayDisplay($aNewArray, "3 Col", Default, 8) Next Func _3ColArray($aInitialArray) ; create a new array with only 3 columns Local $aNewArray[UBound($aInitialArray)][3] For $i = 0 To UBound($aInitialArray) - 1 ; Copy over first 2 columns For $j = 0 To 1 $aNewArray[$i][$j] = $aInitialArray[$i][$j] Next ; Now combime all the others Local $sCombined = "" For $j = 2 To UBound($aInitialArray, 2) - 1 $sCombined &= $aInitialArray[$i][$j] & "|" Next ; And place result in third column - stripping the final delimiter $aNewArray[$i][2] = StringTrimRight($sCombined, 1) Next Return $aNewArray EndFunc M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
ad777 Posted February 20, 2022 Posted February 20, 2022 @gcue maybe you mean like this:(Merge you say's) expandcollapse popup;Example Dataset 1 #include <Array.au3> Local $log_array[10][2] For $x = 0 To UBound($log_array) - 1 For $y = 0 To UBound($log_array, 2) - 1 $log_array[$x][$y] = $x & "-" & $y Next Next _ArrayDisplay($log_array) Local $Clog_array = Keep2Columns($log_array) ;Example Dataset 2 Local $log_array[10][5] For $x = 0 To UBound($log_array) - 1 For $y = 0 To UBound($log_array, 2) - 1 $Clog_array[$x][1] &= $x & "-" & $y Next Next ;_ArrayDisplay($log_array) $Clog_array_1 = Keep2Columns($Clog_array) _ArrayDisplay($Clog_array_1) ;Example Dataset 3 Local $log_array[10][7] For $x = 0 To UBound($log_array) - 1 For $y = 0 To UBound($log_array, 2) - 1 $Clog_array_1[$x][1] &= $x & "-" & $y Next Next $Clog_array_2 = Keep2Columns($Clog_array_1) _ArrayDisplay($Clog_array_2) Func Keep2Columns($array) $columns_to_merge = UBound($array, 2) - 2 If UBound($array, 2) > 2 Then For $x = 0 To UBound($array) - 1 For $y = 0 To $columns_to_merge - 1 Next Next EndIf Return $array EndFunc ;==>Keep2Columns none
gcue Posted February 20, 2022 Author Posted February 20, 2022 both work great! thank you VERY much to each of you!!! Hope you have a great weekend
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