Jump to content

Array guru requested


Recommended Posts

Hi,

I'm facing to a problem which will appear for most of you not really tricky, but I'm not comfortable with array stuff, so prefer asking question is case of someone made this in the past.

I have 2 set of files, text files.

1st one with this format ( systemname;message )

bingo;ERROR Can't be reach port is closed

pppp;system OK

typo;System OK

Ray;ERROR Can't be reach port is closed

blush;ERROR Can't be reach port is closed

bingo;system OK

2nd FILE ( domain;system name ):

HP;ppp

HP;bingo

IBM;typo

COMPAQ;blush

DELL;ray

EXPECTED RESULT :

I would like to match data, to a final txt files ( preferably an html output ) sorted or not :

HP

ppp System OK

bingo System OK

IBM

typo System OK

COMPAQ

blush ERROR Can't be reach port is closed

DELL

ray ERROR Can't be reach port is closed

Does someone have an idea or already realised this kind of stuff :)

Many thanks in advane for you help

Link to comment
Share on other sites

Here's how I would do it:

Create a 2-d look-up array for computers and domains. Populate it with the second file. Set it up so that it is a 2d array, where [x][0] = Domain and [x][1] = Compupter.

Setup a 2nd 2d array for computers and status messages. Populate it with the data from the first file. Set it up so that [x][0] = computer name and [x][1] = message.

Now sort both arrays by the first element of the 2d dimension (using _ArraySort)

Now, to write the final output file:

Open the file in write mode

Write the name of the first domain in the list to the file

loop through the domain list, getting the name of each computer

loop through the computers list, looking for the computer you are referencing. Write the message(s) to the file

Loop to the next computer in the domain

Loop to the next domain in the list, write the name of that domain to the file

close the file

Link to comment
Share on other sites

Here's how I would do it:

Create a 2-d look-up array for computers and domains.  Populate it with the second file.  Set it up so that it is a 2d array, where [x][0] = Domain and [x][1] = Compupter.

Setup a 2nd 2d array for computers and status messages.  Populate it with the data from the first file.  Set it up so that [x][0] = computer name and [x][1] = message.

Now sort both arrays by the first element of the 2d dimension (using _ArraySort)

Now, to write the final output file:

Open the file in write mode

Write the name of the first domain in the list to the file

loop through the domain list, getting the name of each computer

loop through the computers list, looking for the computer you are referencing.  Write the message(s) to the file

Loop to the next computer in the domain

Loop to the next domain in the list, write the name of that domain to the file

close the file

<{POST_SNAPBACK}>

Thanks for for it, any code examples :)
Link to comment
Share on other sites

For both files: Use _FileReadToArray to read the entire file into an array. Then make a 2d array brokendown using StringSplit:

;first, the system to message array
$aTemp = _FileReadToArray('file1.txt')
Dim $aSysMsg[UBound($aTemp)][2]
for $i = 0 to UBound($aTemp) - 1
    $aTemp2 = StringSplit($aTemp[$i])
    $aSysMsg[$i][0] = $aTemp[1]
    $aSysMsg[$i][1] = $aTemp[2]
next
;next the domain to system lookup
$aTemp = _FileReadToArray('file2.txt')
Dim $aDomSys[UBound($aTemp)][2]
for $i = 0 to UBound($aTemp) - 1
    $aTemp2 = StringSplit($aTemp[$i])
    $aSysMsg[$i][0] = $aTemp[1]
    $aSysMsg[$i][1] = $aTemp[2]
next

Then sort both arrays using _ArraySort:

_ArraySort($aSysMsg)
_ArraySort($aModSys)

Now 2 nested loops, 1 to loop through the domain list, and one to loop through the systems in that domain:

Dim $CurDom = ''
for $i = 0 to UBound($aDomSys) - 1
  If $aDomSys[$i][0] <> $CurDom Then
    $CurDom = $aDomSys[$i][0]
    MsgBox(0,'Domain',$CurDom)
  EndIf
  For $j = 0 to UBound($aSysMsg) - 1
    If $aSysMsg[$j][0] = $aDomSys[$i][1] Then
      MsgBox(0,'System',$aSysMsg[$j][0] & '=' & $aSysMsg[$j][1])
    EndIf
  Next;$j
Next;$i

See how that works?

The list $aDomSys contains a list where [x][0] = a domain name, and [x][1] = a system on that domain.

The list $aSysMsg contains a list where [x][0] = a system name and [x][1] = a message associate with that system.

The example is very basic, and will be low on large lists, but it should give you an idea of the logic behind it.

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...