COD3369 Posted August 6, 2013 Share Posted August 6, 2013 i want to delete some lines from a text file. i want to delete line number 1 to 57 any idea how? Link to comment Share on other sites More sharing options...
FireFox Posted August 6, 2013 Share Posted August 6, 2013 Hi,This question was asked a dozen of times so yes you can.Br, FireFox. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 6, 2013 Moderators Share Posted August 6, 2013 verma123,You could read the file into an array with _FileReadToArray and then write it back using FileWriteFromArray but setting the $iBase parameter to 58. Or use_FileWriteToLine in a loop to delete the required lines - in this case you would either need to loop from line #57 up or continually delete just the first line. 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...
czardas Posted August 6, 2013 Share Posted August 6, 2013 (edited) _FileWriteToLine() is the function you need. Too late. M23 got there before me. Edited August 6, 2013 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
COD3369 Posted August 6, 2013 Author Share Posted August 6, 2013 Melba23 any example ? 1. autoit is cool 2. autoit is cool 3 autoit is cool 4 autoit is cool 5 autoit is cool 6 autoit is cool 7 autoit is cool 8 autoit is cool 9 autoit is cool delete line number 4 to 7 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 6, 2013 Moderators Share Posted August 6, 2013 verma123,And what have you tried that has not worked? I gave you enough hints. 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...
COD3369 Posted August 6, 2013 Author Share Posted August 6, 2013 #include <File.au3> _FileReadToArray( @ScriptDir & "\log.html", $acontent for $i = 1 to 56 _FileWriteToLine( @ScriptDir & "\log.html", , "" , 0 ) Next Link to comment Share on other sites More sharing options...
Danyfirex Posted August 6, 2013 Share Posted August 6, 2013 (edited) Hi. maybe something like this. #include <File.au3> #include <Array.au3> Local $aRecords If Not _FileReadToArray("1.txt", $aRecords) Then MsgBox(4096, "Error", " Error reading log to Array error:" & @error) Exit EndIf For $x = 1 To $aRecords[0] MsgBox(0, 'Record:' & $x, $aRecords[$x]) Next _ArrayDelete($aRecords,4) _ArrayDelete($aRecords,7-1) _FileWriteFromArray("2.txt",$aRecords,1) saludos Edited August 6, 2013 by Danyfirex Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 6, 2013 Moderators Share Posted August 6, 2013 verma123,And does that look like what I suggested? Go and read again what I wrote - I gave you 2 possible solutions and you have mixed them up in the same script. First Solution: Read the file into an array and then rewrite it but not from the same start point.Second Solution: Loop through the file using _FileWriteToLine and delete the lines in a loop. Have you even looked at the _FileWriteToLine page in the Help file? Does the syntax you have used look as if it will work? Where is the $iLine parameter? Are you sure that the $fOverWrite parameter should be set to 0 if you want to delete lines?Over to you for a better effort! 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 August 6, 2013 Moderators Share Posted August 6, 2013 verma123,It is not that difficult. Save those few lines as "Cool.txt" and then run this:#include <File.au3> #include <Array.au3> Local $aLines _FileReadToArray("Cool.txt", $aLines) ; Delete first 3 lines _FileWriteFromArray("Cool-Array-Start.txt", $aLines, 4) ; Delete lines from middle For $i = 7 to 4 Step -1 _ArrayDelete($aLines, $i) Next _FileWriteFromArray("Cool-Array-Mid.txt", $aLines, 1) ; Delete lines in a loop FileCopy("Cool.txt", "Cool_WriteToLine.txt", $FC_OVERWRITE) For $i = 7 to 4 Step -1 _FileWriteToLine("Cool_WriteToLine.txt", $i, "", 1) NextI hope all that is clear enough for you to develop it to fit your requirements. 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...
Malkey Posted August 6, 2013 Share Posted August 6, 2013 Here is a regular expression replace method. Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase ; ------------- Create File -------------- Local $sFileName = "Test9Lines.txt" Local $sFileContents For $i = 1 To 9 $sFileContents &= $i & ". autoit is cool" & @CRLF Next If FileExists($sFileName) Then FileDelete($sFileName) EndIf FileWrite($sFileName, StringTrimRight($sFileContents, 2)) ShellExecute($sFileName) WinWaitActive($sFileName) ; ----------> End of Create File --------- Local $sNewFileName = "TestMinusLines.txt" Local $iStart = 4 Local $iTo = 7 If $iStart < 1 Then $iStart = 1 ; First line is line #1. If FileExists($sNewFileName) Then FileDelete($sNewFileName) EndIf FileWrite($sNewFileName, StringRegExpReplace(FileRead($sFileName), "(?s)((\V*\v*){" & $iStart - 1 & "})(\V+\v*){" & ($iTo - $iStart + 1) & "}(.*$)", "\1\4")) ShellExecute($sNewFileName) ;Tidy up files WinWaitActive($sNewFileName) FileDelete($sFileContents) FileDelete($sNewFileName) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 6, 2013 Moderators Share Posted August 6, 2013 Malkey,I was having an internal wager whether it would be you or jchd who posted an SRE solution - my left hand won! M23 COD3369 1 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...
jchd Posted August 6, 2013 Share Posted August 6, 2013 I was away. COD3369 1 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 hereRegExp tutorial: enough to get startedPCRE 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 More sharing options...
COD3369 Posted August 7, 2013 Author Share Posted August 7, 2013 Guys you rocked !! Melba23 Malkey Danyfirex its working flawlessly thank you very much guys love you all Link to comment Share on other sites More sharing options...
iahngy Posted August 9, 2013 Share Posted August 9, 2013 Hi Malky, in this line, FileWrite($sNewFileName, StringRegExpReplace(FileRead($sFileName), "(?s)((\V*\v*){" & $iStart - 1 & "})(\V+\v*){" & ($iTo - $iStart + 1) & "}(.*$)", "\1\4")) what does {" & $iStart - 1 & "} mean? and ((\V*\v*){" & $iStart - 1 & "}) ...does the outside parenthesis represent for \2 ? Link to comment Share on other sites More sharing options...
AZJIO Posted August 9, 2013 Share Posted August 9, 2013 My other projects or all 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