jerem488 Posted July 21, 2009 Share Posted July 21, 2009 (edited) Hello I have a text file with numbers on each line. But whenever I have a series of 4 lines related, like this : 1) 32 44 89 134 78 2) 87 45 66 11 22 3) 32O 34 98 14 38 4) 29 55 71 99 39 And if one of the 4 lines containing "SK", we remove 4 lines. THanks Edited July 21, 2009 by jerem488 Qui ose gagneWho Dares Win[left]CyberExploit[/left] Link to comment Share on other sites More sharing options...
PsaltyDS Posted July 21, 2009 Share Posted July 21, 2009 Hello I have a text file with numbers on each line. But whenever I have a series of 4 lines related, like this : 1) 32 44 89 134 78 2) 87 45 66 11 22 3) 32O 34 98 14 38 4) 29 55 71 99 39 And if one of the 4 lines containing "SK", we remove 4 lines. THanks What? Is there a question in there...? Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
jerem488 Posted July 21, 2009 Author Share Posted July 21, 2009 How to remove these 4 lines if one of them contain "SK" ? Qui ose gagneWho Dares Win[left]CyberExploit[/left] Link to comment Share on other sites More sharing options...
PsaltyDS Posted July 21, 2009 Share Posted July 21, 2009 How to remove these 4 lines if one of them contain "SK" ?You can't delete data in the middle of the file without rewriting the file from that point to the end. The easiest way would be _FileReadToArray(), edit the array as required (i.e. with _ArrayDelete()), then _FileWriteFromArray(). Or you could read the whole file into a string variable, manipulate that, then overwrite it back. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
bogQ Posted July 21, 2009 Share Posted July 21, 2009 this can help FileReadLine() StringInStr() _FileWriteToLine() _FileWriteToLine($sFile, $iLine, $sText[, $fOverWrite = 0]) Remarks If _FileWriteToLine is called with $fOverWrite as 1 and $sText as "", it will delete the line TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost. Link to comment Share on other sites More sharing options...
jerem488 Posted July 21, 2009 Author Share Posted July 21, 2009 yes but if it's the fourth line that contains "SK", how to remove the previous 3 lines ??? Qui ose gagneWho Dares Win[left]CyberExploit[/left] Link to comment Share on other sites More sharing options...
bogQ Posted July 21, 2009 Share Posted July 21, 2009 (edited) _FileWriteToLine($sFile, $iLine-1, "", 1)_FileWriteToLine($sFile, $iLine-2, "", 1)_FileWriteToLine($sFile, $iLine-3, "", 1) edit youl only need to call -3 three times or something like that, its same if you work with arrow i supose on its countItl b nice to see what way do you read the file so that anyone can help you, any codes? Edited July 21, 2009 by bogQ TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost. Link to comment Share on other sites More sharing options...
PsaltyDS Posted July 21, 2009 Share Posted July 21, 2009 edit youl only need to call -3 three times or something like that, its same if you work with arrow i supose on its countItl b nice to see what way do you read the file so that anyone can help you, any codes?Good catch. I had forgotten you could do that with _FileWriteToLine(): RemarksIf _FileWriteToLine is called with $fOverWrite as 1 and $sText as "", it will delete the line. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
jerem488 Posted July 22, 2009 Author Share Posted July 22, 2009 I have a little problem. the problem is the condition if the first line contain "SK" ?? Bacause if the first line contain "SK", the program don't must copy this line and 3 lines after this line. I have this code : $File = FileOpen("C:\File.txt", 0) If $File = -1 Then MsgBox(0, "Erreur", "Impossible d'ouvrir le fichier.") Exit EndIf ; Read in lines of text until the EOF is reached While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop If StringInStr($line,"2)") And StringInStr($line,"INC") Then $NombresLignes = _FileCountLines("c:\File2.txt") _FileWriteToLine("c:\File_2.txt", $NombresLignes-1, "", 1) ElseIf StringInStr($line,"3)") And StringInStr($line,"INC") Then _FileWriteToLine("c:\File2.txt", $NombresLignes-1, "", 1) _FileWriteToLine("c:\File2.txt", $NombresLignes-2, "", 1) Else ;~ If Not StringInStr($line,"1)") And StringInStr($line,"INC") Then FileWriteLine("C:\File2.txt", $line) ;~ EndIf EndIf Wend FileClose($file) Qui ose gagneWho Dares Win[left]CyberExploit[/left] Link to comment Share on other sites More sharing options...
somdcomputerguy Posted July 22, 2009 Share Posted July 22, 2009 Perhaps this is of assistance.. Autoit Wrappers - AutoIt Forums - Page 6 - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
bogQ Posted July 22, 2009 Share Posted July 22, 2009 if i understand correct you need something simulat to this expandcollapse popup#Include <File.au3> Global $todelite = "",$z = 0 $File = FileOpen("test.txt", 0) If $File = -1 Then MsgBox(0, "Erreur", "Impossible d'ouvrir le fichier.") Exit EndIf $lines = _FileCountLines("test.txt") For $x = 1 To $lines $line = FileReadLine($file,$x) If StringInStr($line,"sk") Then Select Case StringLeft($line,1) = "1" If $todelite = "" Then $todelite = $x+3 Else $todelite = $todelite&";"&$x+3 EndIf $z = $z+4 _FileWriteToLine("test2.txt",$z-3,FileReadLine($file,$x+0), 1) _FileWriteToLine("test2.txt",$z-2,FileReadLine($file,$x+1), 1) _FileWriteToLine("test2.txt",$z-1,FileReadLine($file,$x+2), 1) _FileWriteToLine("test2.txt",$z-0,FileReadLine($file,$x+3), 1) Case StringLeft($line,1) = "2" If $todelite = "" Then $todelite = $x+2 Else $todelite = $todelite&";"&$x+2 EndIf Case StringLeft($line,1) = "3" If $todelite = "" Then $todelite = $x+1 Else $todelite = $todelite&";"&$x+1 EndIf Case StringLeft($line,1) = "4" If $todelite = "" Then $todelite = $x Else $todelite = $todelite&";"&$x EndIf EndSelect EndIf Next FileClose($file) MsgBox(0,"This lines i need to delite",$todelite) $delite = StringSplit($todelite,";") If IsArray($delite) Then For $y = $delite[0] To 1 Step -1 _FileWriteToLine("test.txt", $delite[$y]-3, "", 1) _FileWriteToLine("test.txt", $delite[$y]-3, "", 1) _FileWriteToLine("test.txt", $delite[$y]-3, "", 1) _FileWriteToLine("test.txt", $delite[$y]-3, "", 1) Next EndIf test.txt file for testing 1) 01 0 0 0 0 2) 02 0 0 0 0 3) 03 0 0 0 0 4) 04 0 0 0 0 1) 05 0 0 0 0 2) 06 0 0 0 0 3) 07 0 0 0 0 4) 08 0 0 0 0 1) 09 0 0 0 0 2) 10 0 0 0 0 3) 11 0 0 0 0 4) 12 0 0 0 0 1) 13 0 0 0 sk 2) 14 0 0 0 0 3) 15 0 0 0 0 4) 16 0 0 0 0 1) 17 0 0 0 0 2) 18 0 0 0 0 3) 19 0 0 0 0 4) 20 0 0 0 0 1) 21 0 0 0 0 2) 22 0 0 0 0 3) 23 0 0 0 0 4) 24 0 0 0 0 1) 25 0 0 0 0 2) 26 0 0 0 sk 3) 27 0 0 0 0 4) 28 0 0 0 0 1) 29 0 0 0 sk 2) 30 0 0 0 0 3) 31 0 0 0 0 4) 32 0 0 0 0 1) 33 0 0 0 0 2) 34 0 0 0 sk 3) 35 0 0 0 0 4) 36 0 0 0 0 dont forget to create test2.txt for output from lines that are with "1)" and have "sk" on them when testing TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost. Link to comment Share on other sites More sharing options...
GEOSoft Posted July 22, 2009 Share Posted July 22, 2009 If I understand you properly, if any of the lines contains SK, you want to delete all of the files contents. If StringInString(FileRead("somefile.txt"), "SK") Then $hFile = FileOpen("somefile.txt", 2) FileClose($hFile) EndIf George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" 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