justsomenoob Posted July 28, 2022 Share Posted July 28, 2022 Hi First of all, alot of this stuff is too technical for me even after looking through the help and examples so i am wondering if anybody can help me put my request together What i want to do is as follows.... Copy a range of lines and columns to another range of lines and columns of a new text file, for example the source text file lines 15 to 19 with columns 22 to 24 Then do the same thing with different ranges of lines and columns but append them to the end of the first range (append to end of line, not new rows) Repeat the process with new ranges until i am finished. Any range examples will do, i can easily adjust them The output file would look something like... Line61... somestuffhere CopiedStuffHere AppendedStuffHere MoreAppendedStuffHere ... Line62... somestuffhere CopiedStuffHere AppendedStuffHere MoreAppendedStuffHere ... Line63... somestuffhere CopiedStuffHere AppendedStuffHere MoreAppendedStuffHere ... Line64... somestuffhere CopiedStuffHere AppendedStuffHere MoreAppendedStuffHere ... Line65... somestuffhere CopiedStuffHere AppendedStuffHere MoreAppendedStuffHere ... Is that possible ? Link to comment Share on other sites More sharing options...
Nine Posted July 28, 2022 Share Posted July 28, 2022 (edited) 13 hours ago, justsomenoob said: Is that possible ? Yes. See FileReadLine with line number to get a specific line. See StringMid to read in a middle of a line. The rest is just a loop... Edited July 28, 2022 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
justsomenoob Posted July 28, 2022 Author Share Posted July 28, 2022 7 minutes ago, Nine said: Yes. See FileRead with line number to get a specific line. See StringMid to read in a middle of a line. The rest is just a loop... Ok sounds great but i don't know how to put it all together I found this in another topic and modified it but it only does lines. No idea how to get the columns $sFile = "D:\textin.txt" $sRead = FileRead($sFile) $aStrings = StringSplit($sRead, @CRLF, 1) $sResult = "" For $i = 15 To 19 $sResult &= $aStrings[$i] & @CRLF Next $hFile = FileOpen ("D:\textout.txt", 2) FileWrite($hFile, $sResult) FileClose($hFile) Link to comment Share on other sites More sharing options...
Subz Posted July 28, 2022 Share Posted July 28, 2022 See _FileReadToArray and use the $sDelimiter flag, to specify how the columns are identified. Link to comment Share on other sites More sharing options...
justsomenoob Posted July 28, 2022 Author Share Posted July 28, 2022 4 minutes ago, Subz said: See _FileReadToArray and use the $sDelimiter flag, to specify how the columns are identified. Sounds great, if only i knew how to put it all together. My ability is limited to manipulating an already working result Anyone here to kindly put it all together ? Link to comment Share on other sites More sharing options...
Subz Posted July 28, 2022 Share Posted July 28, 2022 The helpfile has examples, its difficult to assist when we don't know what the format of the file you're reading is, i.e. is it tab delimited, comma etc... Link to comment Share on other sites More sharing options...
justsomenoob Posted July 28, 2022 Author Share Posted July 28, 2022 9 minutes ago, Subz said: The helpfile has examples, its difficult to assist when we don't know what the format of the file you're reading is, i.e. is it tab delimited, comma etc... It's just a text file with a bunch of text and other stuff. No special formatting or anything Anyway i came up with this but the output still only captures the lines. Messagebox for columns is empty. I really don't know what i am doing #include <StringConstants.au3> #include <MsgBoxConstants.au3> $sFile = "D:\textin.txt" $sRead = FileRead($sFile) $aLines = StringSplit($sRead, @CRLF, 1) $sResult = "" For $i = 73 To 75 $sResult &= $aLines[$i] & @CRLF $aColumns = StringMid($aLines, 10, 5) Next $hFile = FileOpen ("D:\textout.txt", 2) FileWrite($hFile, $sResult) FileClose($hFile) MsgBox($MB_SYSTEMMODAL, "", $aColumns) Link to comment Share on other sites More sharing options...
Subz Posted July 28, 2022 Share Posted July 28, 2022 What are the columns you're referring to, please paste example of the source text and then how you want that text formatted. When you mention columns I'm imaging a table for example: Row1Column1, Row1Column2, Row1Column3 Row2Column1, Row2Column2, Row2Column3 etc... Link to comment Share on other sites More sharing options...
justsomenoob Posted July 28, 2022 Author Share Posted July 28, 2022 6 minutes ago, Subz said: What are the columns you're referring to, please paste example of the source text and then how you want that text formatted. When you mention columns I'm imaging a table for example: Row1Column1, Row1Column2, Row1Column3 Row2Column1, Row2Column2, Row2Column3 etc... The source text is mostly words but it changes after a process and that process could be weeks or months away. All i need is to grab x amount of lines and x amount of columns to copy. As you can see in my last example i used lines 73 to 75 and columns 10 to 15 (10 to 15 was in the help example so i kept it). The range is whatever you wwant it to be, it's just where and how to place the right code, which is beyond my ability. Use any text file filled with letters or whatever and use any range to copy lines and columns. A working result is all i need, then i can change the lines and columns myself Link to comment Share on other sites More sharing options...
Nine Posted July 28, 2022 Share Posted July 28, 2022 (edited) Here with the FileReadLine method : #include <Constants.au3> Local $hFile = FileOpen("textin.txt") Local $sResult, $sLine, $sColumn For $i = 3 To 5 $sLine = FileReadLine($hFile, $i) $sResult &= $sLine & @CRLF $sColumn &= StringMid($sLine, 10, 5) & @CRLF Next FileClose($hFile) $hFile = FileOpen ("textout.txt", 2) FileWrite($hFile, $sResult) FileClose($hFile) MsgBox($MB_SYSTEMMODAL, "", $sColumn) Edited July 28, 2022 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
justsomenoob Posted July 29, 2022 Author Share Posted July 29, 2022 5 hours ago, Nine said: Here with the FileReadLine method : Getting there. It writes the whole lines and the columns show in the messagebox. Now just need it to write those columns only Link to comment Share on other sites More sharing options...
justsomenoob Posted July 29, 2022 Author Share Posted July 29, 2022 I got it to write just the column but it only does 1 line For $i = 3 To 5 $sLine = FileReadLine($hFile, $i) $sResult &= $sColumn $sColumn &= StringMid($sLine, 10, 5) & @CRLF Next Link to comment Share on other sites More sharing options...
justsomenoob Posted July 29, 2022 Author Share Posted July 29, 2022 I got it to write 3 lines and columns by rearranging a line and removing an & Next step is to get it to write to a line and column instead of the first line and column, or just append to the end of the line #include <Constants.au3> Local $hFile = FileOpen ("D:\textin.txt") Local $sResult, $sLine, $sColumn For $i = 73 To 75 $sLine = FileReadLine($hFile, $i) $sColumn &= StringMid($sLine, 14, 21) & @CRLF $sResult = $sColumn Next FileClose($hFile) $hFile = FileOpen ("D:\textout.txt", 2) FileWrite($hFile, $sResult) FileClose($hFile) MsgBox($MB_SYSTEMMODAL, "", $sColumn) Link to comment Share on other sites More sharing options...
Nine Posted July 29, 2022 Share Posted July 29, 2022 $sResult is redondant and useless. Just use $sColumn only. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy 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