hot202 Posted October 17, 2010 Share Posted October 17, 2010 (edited) Ok so what I would like to know how to do is Move lines around in a .txt file or read from the txt and create a new .txt I have a txt file that has about 200 lines looks like this (line 1) 4642365 53765 8757 963794 (line 2) 8577478 85689 5855 585848 (line 3) 5856954 58477 3534 958468 (line 4) 6947847 58465 6777 756777 (line 5) 7476676 58457 6856 575576 (line 6) 5855764 57466 4746 584784 (line 7) 5635544 58647 5856 674676 (line 8) 5846746 58568 4747 574747 (line 9) 6747476 47474 5847 675856 (line 10) 5857568 58465 5847 575677 (line 11) 5746746 68457 6856 584755 (line 12) 4847558 47474 5758 584858 How would I move line 7 to line 2 Then line 2 to line 3 then line 8 to line 4. Do that for all the lines Would it be easier to make a new txt out of it? Edited October 17, 2010 by hot202 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 17, 2010 Moderators Share Posted October 17, 2010 hot202,Read the file into an array with.......wait for it....._FileReadToArray. Then manipulate the array as you wish - if you have losts of changes to make, you might well find it easier to create a new array and copy the original elements into their new places. Finally rewrite the array to a file with.....you guessed it....._FileWriteFromArray. But be careful of the [0] element. 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...
hot202 Posted October 17, 2010 Author Share Posted October 17, 2010 Are there any examples of moving lines with array Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 17, 2010 Moderators Share Posted October 17, 2010 hot202, What have you tried that has not worked? 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...
whim Posted October 17, 2010 Share Posted October 17, 2010 Then manipulate the array as you wish - if you have losts of changes to make, you might well find it easier to create a new array and copy the original elements into their new places. It might also be interesting to check out _ArraySwap() hth,whim Link to comment Share on other sites More sharing options...
hot202 Posted October 17, 2010 Author Share Posted October 17, 2010 Sorry Melba23 I havnt tried yet. I posted this on my phone. Thanks for the help Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 17, 2010 Moderators Share Posted October 17, 2010 hot202, You know where we are if you run into problems. Have fun! 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...
hot202 Posted October 18, 2010 Author Share Posted October 18, 2010 this seems to work. Is it the right way to do it? Im not sure about the For and the $NewLine is there a better way to do that? #include <array.au3> #Include <File.au3> Dim $FileList _FileReadToArray(@ScriptDir & "\PG5.txt",$FileList) $Newline = 0 For $i = 47 To $FileList[0] $Newline = $Newline +2 _ArrayInsert($FileList, $Newline, $FileList[$i]) _ArrayDelete($FileList, $i + 1) Next _FileWriteFromArray(@ScriptDir & "\Test.txt", $FileList, 1) Switch @Error Case 1 MsgBox(1,"ERROR", "Error opening specified file") Case 2 MsgBox(1,"ERROR", "Input is not an Array") Case 3 MsgBox(1,"ERROR", "Error writing to file") case Else MsgBox(1,"DONE", "File Created") EndSwitch Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 18, 2010 Moderators Share Posted October 18, 2010 hot202,Is it the right way to do it?If it gets you what you want then the answer can only be "Yes!". is there a better way to do that?As I am unsure exactly what you are trying to do, that is very difficult to say. But see answer 1 above! 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...
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