Jump to content

[SOLVED] combine Arrays respectively


Recommended Posts

Hi dear friends!, i'm sorry for creating a new thread (a new problem), i have over than 9 lists that i want to combine them to be this (in this example, there are 3 test files):

TEST.png.6ef3c654296a307d4200527624c38fb1.thumb.png.baa22b5dc305653db6836279fbe726c5.png

I've written a little code for splitting main information, but i really confused how to make results as "Output.txt", here is that code:
 

$sRegex_1 = StringRegExp(FileRead("1.txt"), '(?s:(?<=\=\=\r\n)(.*?)(?=\r\n\=\=))', 3)
$sRegex_2 = StringRegExp(FileRead("2.txt"), '(?s:(?<=\=\=\r\n)(.*?)(?=\r\n\=\=))', 3)
$sRegex_3 = StringRegExp(FileRead("3.txt"), '(?s:(?<=\=\=\r\n)(.*?)(?=\r\n\=\=))', 3)

For $i = 0 To UBound($sRegex_1) - 1
    ConsoleWrite($sRegex_1[$i] & @CRLF)
    For $j = 0 To UBound($sRegex_2) - 1
        ConsoleWrite($sRegex_2[$j] & @CRLF)
        For $k = 0 To UBound($sRegex_3) - 1
            ConsoleWrite($sRegex_3[$k] & @CRLF)
        Next
    Next
Next

 

Edited by Colduction
Link to post
Share on other sites

You could have posted sample input files instead of an image, that would have saved time.

Local $s = FileRead("1.txt") & @CRLF & FileRead("2.txt") & @CRLF & FileRead("3.txt")
$s = StringRegExpReplace($s, "==\R", "", 2)
Local $a = StringRegExp($s, "(?:\d+\w+\R){2}[-=]{2}\R?", 3)
_ArraySort($a)
Local $sOut = _ArrayToString($a, "", -1, -1, "")
ConsoleWrite($sOut & @LF)

If you have decimal parts > 9 then use a version of _ArraySort which allows numerical sort. Lots of examples already posted.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to post
Share on other sites
11 hours ago, jchd said:

You could have posted sample input files instead of an image

Here you are:

1.txt

2.txt

3.txt

11 hours ago, jchd said:

If you have decimal parts > 9 then use a version of _ArraySort which allows numerical sort. Lots of examples already posted.

In fact, i didn't show main information because it's private, but totally data forms are as showed examples (important datas are between ==)

Link to post
Share on other sites

Now there is no numeric prefix in the data ... a moving target?

Local $s = FileRead("1.txt") & @CRLF & FileRead("2.txt") & @CRLF & FileRead("3.txt")
$s = StringRegExpReplace($s, "==\R", "", 2)
Local $a = StringRegExp($s, "(?:\w+\R){2}==\R?", 3)
_ArraySort($a)
Local $sOut = _ArrayToString($a, "", -1, -1, "")
ConsoleWrite($sOut & @LF)

Does that fit your bill?

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to post
Share on other sites

Please stop posting images, it's very painful to the eye.

Are you sure the files exist in the current working directory?

Because this works for me:

>Running:(3.3.15.1):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\...\t.au3"    
+>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+BREAK to Stop.
aa
aa
==
bb
bb
==
bb
bb
==
bb
bb
==
cc
cc
==
+>15:18:23 AutoIt3.exe ended.rc:0
+>15:18:23 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 1.359

 

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to post
Share on other sites
10 minutes ago, jchd said:

Please stop posting images, it's very painful to the eye.

Sorry, i just wanted to show you what happend.

10 minutes ago, jchd said:

Are you sure the files exist in the current working directory?

Yes!

10 minutes ago, jchd said:

aa aa == bb bb == bb bb == bb bb == cc cc ==

This is not the result that i want, are you decreased some texts in sample files? the output should be this:

Output.txt

Edited by Colduction
Link to post
Share on other sites
4 hours ago, Colduction said:

are you decreased some texts in sample files?

I copied the sample text files you provided yourself. That is:
1.txt

==
aa
aa
==
aa
aa
==

2.txt
 

==
bb
bb
==
bb
bb
==
bb
bb
==

3.txt
 

==
cc
cc
==

Using the code below, I get:
 

Local $s = FileRead("1.txt") & @CRLF & FileRead("2.txt") & @CRLF & FileRead("3.txt")
Local $a = StringRegExp($s, "==\R(?:\w+\R){2}\R?", 3)
_ArraySort($a)
Local $sOut = _ArrayToString($a, "", -1, -1, "") & "=="
ConsoleWrite($sOut & @LF)


Result:
==
aa
aa
==
aa
aa
==
bb
bb
==
bb
bb
==
bb
bb
==
cc
cc
==

I don't understand why you expect extra entries to get in the way and where the numbers come from.

Can you explain the wanted logic in plain details?

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to post
Share on other sites

I post (again) my last code which, given the data in the first post provides you with the result you expect in your last post.

Local $s = FileRead("1.txt") & @CRLF & FileRead("2.txt") & @CRLF & FileRead("3.txt")
Local $a = StringRegExp($s, "==\R(?:\w+\R){2}\R?", 3)
_ArraySort($a)
Local $sOut = _ArrayToString($a, "", -1, -1, "") & "=="
ConsoleWrite($sOut & @LF)

This is my last try to catch the butterfly.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to post
Share on other sites
1 hour ago, Colduction said:

But i should think about arrays overflows, if first array completed and second array not completed, then continue second array.

Which "array overflow"?  You concatenate input files, split the result in an 1D array, sort it then glue entries together to build output.
AutoIt arrays can hold 16 million entries. Do you expect your files to contain more than that?

What does "array completed" means.

Aren't you happy with the result provided by my last code?

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to post
Share on other sites
15 hours ago, jchd said:

Which "array overflow"?  You concatenate input files, split the result in an 1D array, sort it then glue entries together to build output.
AutoIt arrays can hold 16 million entries. Do you expect your files to contain more than that?

No, i don't mean that, for example i have an array with 2 row and i have to get data via loop, but in this loop i inserted another array with 3 rows, when first array's loop completed, remains 1 row from second array that will not be showed, this is what I mean by overflow and this is my main problem in this thread! RESPECTIVELY AND PERIODIC.

15 hours ago, jchd said:

Aren't you happy with the result provided by my last code?

Sorry sir, no, but thanks for your reply.
I hope that this problem will be solved :(

Link to post
Share on other sites

Like this ? :

#include <Array.au3>
#include <String.au3>


$one = _StrToArr(FileRead("1.txt"))
$two = _StrToArr(FileRead("2.txt"))
$tre = _StrToArr(FileRead("3.txt"))

$end = False

$max1 = UBound($one) / 2
$max2 = UBound($two) / 2
$max3 = UBound($tre) / 2

$max = $max1
If $max2 > $max Then $max = $max2
If $max2 > $max Then $max = $max3

cw("==")
For $x = 0 To $max

    If $x < $max1 Then
        cw($one[($x * 2)])
        cw($one[($x * 2) + 1])
        cw("==")
    EndIf

    If $x < $max2 Then
        cw($two[($x * 2)])
        cw($two[($x * 2) + 1])
        cw("==")
    EndIf

    If $x < $max3 Then
        cw($tre[($x * 2)])
        cw($tre[($x * 2) + 1])
        cw("==")
    EndIf
Next

Func cw($txt)
    ConsoleWrite($txt & @CRLF)
EndFunc   ;==>cw

Func _StrToArr($s)
    Local $a = _StringBetween($s, @CRLF, @CRLF)
    For $x = UBound($a) - 1 To 0 Step -1
        If $a[$x] = "==" Then _ArrayDelete($a, $x)
    Next
    Return $a
EndFunc   ;==>_StrToArr

 

Link to post
Share on other sites
  • Colduction changed the title to [SOLVED] combine two Arrays respectively

Jeez, I now see what you want.  The first problem is that you never explained yourself clearly, and your first example matches what would result from a sort, once elements are split out.

Another skin for that cat, provided the files have the correct format:

Local $iNbFiles = 3
Local $aFiles[$iNbFiles][3] = [["1.txt"], ["2.txt"], ["3.txt"]]

Local Static $iMax = 0
For $i = 0 To UBound($aFiles) - 1
    $aFiles[$i][1] = StringRegExp(FileRead($aFiles[$i][0]), "==\R(?:.+\R){2}", 3)
    $aFiles[$i][2] = UBound($aFiles[$i][1])
    $iMax = _Max($iMax, UBound($aFiles[$i][1]))
Next

Local $sOut, $a
For $i = 0 To $iMax - 1
    For $j = 0 To UBound($aFiles) - 1
        If $i < $aFiles[$j][2] Then $sOut &= ($aFiles[$j][1])[$i]
    Next
Next
$sOut &= "=="

ConsoleWrite($sOut & @LF)

Next time, please, make the minimum effort to fully and clearly explain what you want.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to post
Share on other sites
13 hours ago, jchd said:

The first problem is that you never explained yourself clearly

Yes, i didn't know how to clearing for you to understand what i want! :sweating:

13 hours ago, jchd said:

Next time, please, make the minimum effort to fully and clearly explain what you want.

Roger that!:D:sweating:
At last, i want to say thanks for giving your time on my project!

Link to post
Share on other sites

Another example for your amusement.

#include <Array.au3>

Local $aFiles[][2] = [["1.txt"], ["2.txt"], ["3.txt"]]
Local $iMNCols = 0 ; Maximum Number of Columns (MNC)
Local $sStr = "" ;   This string will be converted into 2D array.

; Files to abbreviated strings
For $i = 0 To UBound($aFiles) - 1
    $aFiles[$i][1] = StringRegExpReplace(FileRead($aFiles[$i][0]), '(?:=+\R)?(\w+)[^=]+(?:=+\R?)?', "\1|") ; De-construct file format.
    StringReplace($aFiles[$i][1], "|", "|")
    $iExt = @extended ;                                @extended contains number of replacements in StringReplace() function.
    $iMNCols = ($iExt > $iMNCols ? $iExt : $iMNCols) ; Get Maximum Number of Columns
Next

; String to 2D array
For $i = 0 To UBound($aFiles) - 1
    $sStr &= StringTrimRight($aFiles[$i][1], 1) & @CRLF ; StringTrimRight() removes trailing "|" .
Next
Local $aData[0][$iMNCols]
_ArrayAdd($aData, StringStripWS($sStr, 2)) ; Append the three rows into the $aData array with $iMNCols number of columns.
_ArrayTranspose($aData) ; Now array has $iMNCols number of rows, with three columns.
;_ArrayDisplay($aData, "", "", 0, Default, "1.txt|2.txt|3.txt")

; 2D array to file re-constructed string with numbers
Local $sRet = "==" & @CRLF
Local $r = 1 ; Counter
For $j = 0 To UBound($aData) - 1
    For $i = 0 To UBound($aData, 2) - 1
        If $aData[$j][$i] <> "" Then
            $sRet &= $r & $aData[$j][$i] & @CRLF & $r & $aData[$j][$i] & @CRLF & "==" & @CRLF
        EndIf
    Next
    $r += 1 ; Increment $r
Next

ConsoleWrite(StringStripWS($sRet, 2) & @CRLF) ; Parameter flag (2) = strip trailing white spaces (@CRLF).

Used the following files with the resultant output.

1.txt:
==
aa
aa
==
aa
aa
==

2.txt:
==
bb
bb
==
bb
bb
==
bb
bb
==
bb
bb
==
bb
bb
==
bb
bb
==

3.txt:
==
cc
cc
==
cc
cc
==
cc
cc
==
cc
cc
==

OUTPUT.txt:
==
1aa
1aa
==
1bb
1bb
==
1cc
1cc
==
2aa
2aa
==
2bb
2bb
==
2cc
2cc
==
3bb
3bb
==
3cc
3cc
==
4bb
4bb
==
4cc
4cc
==
5bb
5bb
==
6bb
6bb
==

 

Link to post
Share on other sites
  • Colduction changed the title to [SOLVED] combine Arrays respectively

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By TheAlienDoctor
      Hi, I was looking into creating a script that would detect if a file exists, then move it (and in some cases rename it, depending on the file) as well as write to a log file.
      The issue is, there is a lot of files that need to be moved, sometimes some files will exist and others won't depending on the use-case. However if a file does exist, it will always be going into the same directory with the same name.
      Currently I have an array nested inside of the array, with each array inside that array having both the old and new directory, and then a For loop to actually run through and do the file transferring. The issue I am having is how to call the Array inside of the array, because how do I specify  which the old directory is and which the new is?
      Global $FileTransfer[2000] = [Global $Dir1[2] = ["original dir 1", "new dir 1"], Global $Dir2[2] = ["original dir 2", "new dir 2"]] For $FileTransfer = [0] To [1] Step +1 If FileExists({original dir}) Then FileMove({original dir}, new dir, 1) FileOpen("log.latest.txt", 1) FileWrite("log.latest.txt", "{original dir} found, moved it to new dir." & @CRLF) FileClose("log.latest.txt") Else FileOpen("log_latest.txt", 1) FileWrite("log_latest.txt", "{original dir} not found, ignoreing it." & @CRLF) FileClose("log_latest.txt") EndIf Next I have put what I want the old and new directory to be for each array in {}, so hopefully its easier to tell which part is working and whats not.

      I am still reasonably new to AutoIT, any help is appreciated. Thankyou
    • By arunkw
      I have a spreadsheet - daily routine which has two columns: activity and time as shown here
      | Activity             | Time     | |----------------------|----------| | Sleep               |  6:00 am | | Toilet              |  6:15 am | | Get ready for gym  |  6:30 am | | Exercise            |  7:50 am | | ... more things      |  9:00 pm | | ... still more       | 10:45 pm | | Sleep               |  6:00 am |   I wanted to find out, say in C1 which activity is current for me using now() I.e., if it’s 6:45am on my watch, it should show me Exercise  in C1 Thanks to Adam D. PE, this formula works like magic to get the result =VLOOKUP(MOD(NOW(),1),{B2:B,A2:A},2,1)   Now, I want to reproduce same result in autoit, how to do that? To have easy solution say, I copy-paste spreadsheet data in array directly in code, right? Use for loop and run the above vlookup function and show the answer using tooltip. How to achieve this? please help.  
    • By goku200
      I have an Autoit script that lists files from a folder into an array list. Is there a way to separate the filenames by an underscore and include the id, version, name and date into separate columns in Excel.
      Example of filename:
      12345_v1.0_TEST Name [12345]_01.01.2022.html
      12345 would be in one column
      v1.0 would be in another column
      TEST Name [12345] would be in another column
      01.01.2022 would be in another column
      .html would be in another column
      Note: filenames always change each day.
      Here is my code that lists the files into column C and then writes the column Headers into Column D, E, F, G. Just need some help with separating them into columns by the _ delimiter
       
    • By mLipok
      Usually when I collect data from DataBase I need to give EndUser a possibility to select rows which should be taken in the processing loop.
      I was searching on the forum and I'm not able to find any UDF or even example of how to select data from array.
      I have my own solutions but I think they are not worth posting on the forum as it is very old code and I am looking for a better solution.

      Could anybody point me to some examples/solutions ?

      Thank you in advance.
      @mLipok
    • By EmilyLove
      I have a string containing the full path of an executable and an array of executables without their paths. I am trying to compare the string to the list in the array and if a match is found, remove it from the array. The entry get removed from the array successfully, and after checking its return result, uses it to update the ubound if it succeeded, but it doesn't want to update to the new value. Any ideas what I am doing wrong? It acts like it is read-only.
      #include <Array.au3> #include <File.au3> Local $sApp_Exe = "F:\App\Nextcloud\nextcloud.exe" Local $aWaitForEXEX = [3, "Nextcloud.exe", "nextcloudcmd.exe", "QtWebEngineProcess.exe"] For $h = 1 To $aWaitForEXEX[0] If StringInStr($sApp_Exe, $aWaitForEXEX[$h]) <> 0 Then $iRet = _ArrayDelete($aWaitForEXEX, $h) If $iRet <> -1 Then $aWaitForEXEX[0] = $iRet ;this line doesn't work. $aWaitForEXEX[0] doesn't update and shortly gives Error: Array variable has incorrect number of subscripts or subscript dimension range exceeded.: _ArrayDisplay($aWaitForEXEX) EndIf Next  
×
×
  • Create New...