jjunior Posted September 19, 2014 Share Posted September 19, 2014 (edited) I have the file.txt with the content below -99.05305 -19.95130 PRODUCT1 -99.05805 -19.99598 PRODUCT2 -59.69598 -00.97666 PRODUCT3 -59.69600 -00.99615 PRODUCT2 -59.59901 -00.93790 MODELO -59.63899 -00.95839 TEST -59.58050 -00.98086 MODE -99.05361 -19.95031 HOMER -59.79698 -00.00990 MASTER -59.81611 -00.19885 PRODUCT1 -98.90587 -10.36600 PRODUCT1 And i want to creat files from this file, example: PRODUCT1.txt with the content below -59.81611 -00.19885 PRODUCT1 -98.90587 -10.36600 PRODUCT1 -99.05305 -19.95130 PRODUCT1 PRODUCT2.txt with the content below -59.69600 -00.99615 PRODUCT2 -59.69600 -00.99615 PRODUCT2 I use the script to create a string separating the file, but I do a script for each string below, would do everything in one script? Sorry my bad english. Thanks in advanced. #include <File.au3> Global $FileArray $file = @ScriptDir & "\Original.txt" ;arquivo original $outputfile = @ScriptDir & "\OK\PRODUCT2.txt" ;arquivo de saída $istring = "PRODUCT2" ; string a ser capturada _FileReadToArray($file, $FileArray) $filecount = 0 $sNewFile_Text = "" ProgressOn("Processando: " & $istring , "Lendo o arquivo Original.txt", "0 Lines") FileDelete ($outputfile) ;apagar o arquivo antigo (pois se não pagar e acumula os alertas) For $i = 1 To $FileArray[0] If StringInStr($FileArray[$i], $istring) Then If $filecount > 0 Then FileWrite($outputfile, $sNewFile_Text) $filecount = $filecount + 1 $sNewFile_Text = $FileArray[$i] & @CRLF Else $sNewFile_Text &= $FileArray[$i] & @CRLF EndIf $Percent = Int(($i / $FileArray[0]) * 100) ProgressSet($Percent, $Percent & " % Completo do arquivo: " & $outputfile) Next ProgressSet(100, "Feito", "Completo") Sleep(1000) ProgressOff() Edited September 19, 2014 by jjunior Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 19, 2014 Moderators Share Posted September 19, 2014 jjunior,Welcome to the AutoIt forums. But in future, please open a new thread like this and do not hijack an old one - particularly when it had only a very tenuous connection to your question. Give me a moment and I will look at the problem. 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 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 19, 2014 Moderators Share Posted September 19, 2014 jjunior,Here is one way you might do it: expandcollapse popup#include <File.au3> Global $aOriginal ; Read file into a 2D array _FileReadToArray(@ScriptDir & "\Original.txt", $aOriginal, $FRTA_COUNT + $FRTA_ENTIRESPLIT, " ") ; Just for display _ArrayDisplay($aOriginal, "Original", Default, 8) ; Extract the final elements from each line and get the unique values Global $aItems = _ArrayExtract($aOriginal, 1, Default, 2, 2) $aItems = _ArrayUnique($aItems) ; Again just for display _ArrayDisplay($aItems, "Unique elements", Default, 8) ; Now for each unique item For $i = 1 To $aItems[0] $sData = "" ; Look through the original array For $j = 1 To $aOriginal[0][0] ; if teh final item matches If $aOriginal[$j][2] = $aItems[$i] Then ; Add it to the string $sData &= $aOriginal[$j][0] & " " & $aOriginal[$j][1] & " " & $aOriginal[$j][2] & @CRLF EndIf Next ; Remove the final @CRLF $sData = StringTrimRight($sData, 2) ; This shows what we have in the data in the SciTE console ConsoleWrite( $aItems[$i] & ".txt" & @CRLF & $sData & @CRLF & @CRLF) ; And this is how you could write it to a file ;$hFile = FileOpen(@ScriptDir & "\" & $aItems[$i] & ".txt", $FO_OVERWRITE) ;FileWrite($hFile, $sData) ;FileClose($hFile) NextPlease ask if you have any questions: 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 Link to comment Share on other sites More sharing options...
jjunior Posted September 19, 2014 Author Share Posted September 19, 2014 (edited) I want to create other files, with the other end of the line below and others that have on file though I did not show. Like this MODELO Fixo - 80.txt -59.59901 -00.93790 MODELO Fixo - 80 kmh TEST Fixo - 70.txt -59.63899 -00.95839 TEST Fixo - 70 kmh MODE Fixo - 60.TXT -59.58050 -00.98086 MODE Fixo - 60 kmh HOMER Fixo - 50.txt -99.05361 -19.95031 HOMER Fixo - 50 kmh Edited September 19, 2014 by jjunior Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 19, 2014 Moderators Share Posted September 19, 2014 jjunior,I imagine it is because the _FileReadToArray function does not return an array. What is the actual delimiter between the elements on each line of the file? I used 4 spaces as that was what was in the text you posted - is it perhaps @TAB? Could I suggest you post an example copy of the file you are actually using - that way we can see the internal structure. 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 Link to comment Share on other sites More sharing options...
jjunior Posted September 19, 2014 Author Share Posted September 19, 2014 The file i was use is link Link to comment Share on other sites More sharing options...
Moderators Solution Melba23 Posted September 19, 2014 Moderators Solution Share Posted September 19, 2014 jjunior,As I suspected: @TAB delimited. This works for me:expandcollapse popup#include <File.au3> Global $aOriginal ; Read file into a 2D array _FileReadToArray(@ScriptDir & "\Original.txt", $aOriginal, $FRTA_COUNT, @TAB) ; Just for display _ArrayDisplay($aOriginal, "Original", Default, 8) ; Extract the final elements from each line and get the unique values Global $aItems = _ArrayExtract($aOriginal, 1, Default, 2, 2) $aItems = _ArrayUnique($aItems) ; Again just for display _ArrayDisplay($aItems, "Unique elements", Default, 8) ; Now for each unique item For $i = 1 To $aItems[0] $sData = "" ; Look through the original array For $j = 1 To $aOriginal[0][0] ; if teh final item matches If $aOriginal[$j][2] = $aItems[$i] Then ; Add it to the string $sData &= $aOriginal[$j][0] & @TAB & $aOriginal[$j][1] & @TAB & $aOriginal[$j][2] & @CRLF EndIf Next ; Remove the final @CRLF $sData = StringTrimRight($sData, 2) ; This shows what we have in the data in the SciTE console ConsoleWrite( $aItems[$i] & ".txt" & @CRLF & $sData & @CRLF & @CRLF) ; And this is how you could write it to a file ;$hFile = FileOpen(@ScriptDir & "\" & $aItems[$i] & ".txt", $FO_OVERWRITE) ;FileWrite($hFile, $sData) ;FileClose($hFile) NextM23 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 Link to comment Share on other sites More sharing options...
jjunior Posted September 19, 2014 Author Share Posted September 19, 2014 This is perfect. The error was (@TAB delimited) Thanks M8. Thanks for the fast help. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 19, 2014 Moderators Share Posted September 19, 2014 jjunior,As always, delighted I could help. 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 Link to comment Share on other sites More sharing options...
jjunior Posted September 19, 2014 Author Share Posted September 19, 2014 Melba23 When a line finish at km/h it´s not possible to save, because the "/". Have a way to remove "km/h" in the name of file? Link to comment Share on other sites More sharing options...
MikahS Posted September 19, 2014 Share Posted September 19, 2014 (edited) ? StringReplace() Edited September 19, 2014 by MikahS Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 19, 2014 Moderators Share Posted September 19, 2014 jjunior,MikahS' suggestion sounds good to me. 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 Link to comment Share on other sites More sharing options...
jjunior Posted September 19, 2014 Author Share Posted September 19, 2014 Thanks Friends, i chage this line and work like a charme. $hFile = FileOpen(@ScriptDir & "\TEMP\" & (Stringreplace($aItems[$i], "km\h", "")) & ".txt", $FO_OVERWRITE) Link to comment Share on other sites More sharing options...
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