gcue Posted May 28, 2008 Posted May 28, 2008 i know that theres a way to replace strings in files but is there a way to DELETE lines containing "some text...." where "..." can be anything
martin Posted May 28, 2008 Posted May 28, 2008 (edited) i know that theres a way to replace strings in files but is there a way to DELETE lines containing "some text...." where "..." can be anythingHi gcue, try this $filename = "testdel.txt" $text = FileRead($filename) $replace = "some text" $text = StringRegExpReplace($text,"\h*\Q" & $replace & "\E.*\cM\cJ","") $hf = FileOpen($filename,2) FileWrite($hf,$text) EDIT:Corrected so does not leave an empty line. Edited May 29, 2008 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
sandin Posted May 28, 2008 Posted May 28, 2008 try this: #Include <File.au3> Global $success = False $file_name = FileOpenDialog("Select file", @ScriptDir, "All files (*.*)", 1+4) $line_text_input = InputBox("Line's text", "Line must contain following text:", "line contains this text") $file_count_lines = _FileCountLines($file_name) for $i = 0 to $file_count_lines $Lines_text_output = FileReadLine($file_name, $i) if StringInStr($Lines_text_output, $line_text_input) then _FileWriteToLine($file_name, $i, "", 1) $success = True ExitLoop EndIf Next if $success = True Then MsgBox(0, "Success", "Line has been deleted") Else MsgBox(0, "Failure", "Line wasn't found") EndIf Some cool glass and image menu | WinLIRC remote controler | Happy Holidays to all... | Bounce the sun, a game in which you must save the sun from falling by bouncing it back into the sky | Hook Leadtek WinFast TV Card Remote Control Msges | GDI+ sliding toolbar | MIDI Keyboard (early alpha stage, with lots of bugs to fix) | Alt+Tab replacement | CPU Benchmark with pretty GUI | Ini Editor - Edit/Create your ini files with great ease | Window Manager (take total control of your windows) Pretty GUI! | Pop-Up window from a button | Box slider for toolbar | Display sound volume on desktop | Switch hotkeys with mouse scroll
gcue Posted May 28, 2008 Author Posted May 28, 2008 hey martin =) that works but it still leaves a blank line. Hi gcue, try this $filename = "testdel.txt" $text = FileRead($filename) $text = StringRegExpReplace($text,"\v\h*\Qsome text\E.*","") $hf = FileOpen($filename,2) FileWrite($hf,$text)
gcue Posted May 28, 2008 Author Posted May 28, 2008 sandin that works great.. im trying to repeat it for all instances and predefine the line to replace heres what i have.. not sure how i can loop it so it will replace all instances #Include <File.au3> Global $success = False $filename = "C:\CRS\Tools\Account_Info\gxm_novell.txt" $line_text_input = "Subject:" $file_count_lines = _FileCountLines($filename) for $i = 0 to $file_count_lines $Lines_text_output = FileReadLine($filename, $i) if StringInStr($Lines_text_output, $line_text_input) then _FileWriteToLine($filename, $i, "", 1) $success = True ExitLoop EndIf Next ShellExecute($filename) try this: #Include <File.au3> Global $success = False $file_name = FileOpenDialog("Select file", @ScriptDir, "All files (*.*)", 1+4) $line_text_input = InputBox("Line's text", "Line must contain following text:", "line contains this text") $file_count_lines = _FileCountLines($file_name) for $i = 0 to $file_count_lines $Lines_text_output = FileReadLine($file_name, $i) if StringInStr($Lines_text_output, $line_text_input) then _FileWriteToLine($file_name, $i, "", 1) $success = True ExitLoop EndIf Next if $success = True Then MsgBox(0, "Success", "Line has been deleted") Else MsgBox(0, "Failure", "Line wasn't found") EndIf
sandin Posted May 28, 2008 Posted May 28, 2008 just delete "ExitLoop" line Some cool glass and image menu | WinLIRC remote controler | Happy Holidays to all... | Bounce the sun, a game in which you must save the sun from falling by bouncing it back into the sky | Hook Leadtek WinFast TV Card Remote Control Msges | GDI+ sliding toolbar | MIDI Keyboard (early alpha stage, with lots of bugs to fix) | Alt+Tab replacement | CPU Benchmark with pretty GUI | Ini Editor - Edit/Create your ini files with great ease | Window Manager (take total control of your windows) Pretty GUI! | Pop-Up window from a button | Box slider for toolbar | Display sound volume on desktop | Switch hotkeys with mouse scroll
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