Jump to content

Recommended Posts

Posted

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!

Posted (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!
 

;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 by gcue
  • Moderators
Posted

gcue,

This is how I would do it:

#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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

@gcue

maybe you mean like  this:(Merge you say's)

;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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...