TuMiM Posted February 23, 2006 Share Posted February 23, 2006 Is there a way to search within the contents of a file for different things and then write them to a file? for example if the file contains test: mytest then write it to a file. If it contains test: mytest2 write it to a file. But the file can contain multiple of these entries so it would have to search for all of them. Is that possible? Link to comment Share on other sites More sharing options...
ChrisL Posted February 23, 2006 Share Posted February 23, 2006 (edited) Do you mean like this? $File = FileOpen ("MyTextfile.txt",0) If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf While 1 $line = FileReadLine ( $File) if @error = -1 then ExitLoop If Stringinstr ($line, "MyString") then FileWriteLine ("MyNewfile.txt", $Line) WEnd FileClose ($File) Edited February 23, 2006 by ChrisL [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
cdkid Posted February 23, 2006 Share Posted February 23, 2006 $var = FileRead("myfile.txt", FileGetSize("myfile.txt")) $var = StringSplit($var, @CRLF, 1) for $i = 0 to $var[0] if StringInStr($var[$i], "test: mytest") then filewriteline("mynewfile.txt",$var[$i]) EndIf Next --like that? ~cdkid AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location is:kan2.sytes.net/publicsvn/mysqlnote: This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: www.hirethebrain.com Hire The Brain HireTheBrain.com Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide! Link to comment Share on other sites More sharing options...
TuMiM Posted February 23, 2006 Author Share Posted February 23, 2006 ok, let's say this file is not really meant to be open as a text file but if you open it with notepad you can do a find with notepad and easily find these entries. Should the fileread command work? It is not working on these files but works fine on a regular txt file. what does fileread use to open the file? Link to comment Share on other sites More sharing options...
cdkid Posted February 23, 2006 Share Posted February 23, 2006 can you attatch the file you want to read from? Because i dont really understand waht you mean. ~cdkid AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location is:kan2.sytes.net/publicsvn/mysqlnote: This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: www.hirethebrain.com Hire The Brain HireTheBrain.com Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide! Link to comment Share on other sites More sharing options...
TuMiM Posted February 23, 2006 Author Share Posted February 23, 2006 (edited) I am looking for anything that is LANG:849064.txt Edited February 23, 2006 by TuMiM Link to comment Share on other sites More sharing options...
randallc Posted February 23, 2006 Share Posted February 23, 2006 (edited) Hi, if you want the whole line, yo can use DOS; [in Search String, separate multiple searches by spaces; check syntax for Findstr] 1. Dim $DosFINDSTRReturn,$Display Opt("RunErrorsFatal", 0) $SearchString='LANG' $DefSwitches='/R/I /c:"'&$SearchString&'"' ; Change only if you know FINDSTR switches well $FileIndiv = @ScriptDir&"\849064.txt" $Answer=@ScriptDir&"\Answer.txt" FileDelete($Answer) FINDSTRAU3($DefSwitches,$FileIndiv,$Answer) RunWait("notepad.exe " & $Answer ,@ScriptDir) ;--------------- FINDSTRAU3 function; Randallc randallc@ozemail.com.au --------------- Func FINDSTRAU3($Switches, $File,$AnswerFile) If StringInStr($File, " ") Then $File = '"' & $File & '"' If StringInStr($AnswerFile, " ") Then $AnswerFile = '"' & $AnswerFile & '"' $Command ='FINDSTR '& $Switches &' '& $File &'>'&$AnswerFile $DosFINDSTRReturn=RunWait( @ComSpec & " /c " & $Command, @SystemDir, @SW_HIDE) EndFunc ;==>FINDSTRAU3OR FileRead works OK; 2.$sTXTLOGFile = @ScriptDir&"\849064.txt" $sTXTLOGFile2 = @ScriptDir&"\sTXTLOGFile2.txt" $var = FileRead($sTXTLOGFile, FileGetSize($sTXTLOGFile)) FileWriteLine ($sTXTLOGFile2, $var) RunWait("notepad.exe " & $sTXTLOGFile2 ,@ScriptDir) if StringInStr($var,"LANG") then $AnswerString="LANG" if StringInStr($var,"LANG2") then $AnswerString="LANG2" MsgBox(0,"","$AnswerString="&$AnswerString) Best, Randall Edited February 23, 2006 by randallc ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW 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