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 comment
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 comment
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 comment
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 comment
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 comment
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 comment
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 comment
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 comment
Share on other sites

10 hours ago, jchd said:

This is my last try to catch the butterfly.

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

Link to comment
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 comment
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 comment
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

 

Some of my script sourcecode

Link to comment
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 comment
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 comment
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 comment
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
 Share

×
×
  • Create New...