jebus495 Posted July 29, 2009 Posted July 29, 2009 #include <file.au3> #include <Array.au3> $lines = _FileCountLines("prepatch.log") $x2 = 1 For $x2 = 1 To $lines $linestring = FileReadLine("prepatch.log", $x2) $split = StringSplit($linestring, " ") For $x = 1 to $split[0] _FileWriteToLine("wordlist2.txt",$x2, $split[$x], 1) Next Next The above will read a text file and put every word on a separate line. It also creates a lot of blank lines in the process so now I need a way to remove blank lines or prevent them in the first place. Dim $aLines Dim $sFile = "wordlist2.txt" _FileReadToArray($sFile, $aLines) _ArrayDelete($aLines,4) FileDelete($sFile) For $i=1 to $aLines[0] If $aLines[$i]<>"" Then FileWriteLine($sFile,$aLines[$i]) Next I found this from searching but I can't seem to get it to work properly...
BuckMaster Posted July 29, 2009 Posted July 29, 2009 (edited) This works, Reads the file then changes it to hex removes the lines that are blank, then changes it back from hex. #include <String.au3> $File = FileRead("File.txt") $FileOut = _StringtoHex($File) $FileEdit = StringReplace($FileOut, "0D0A0D0A", "0D0A") ConsoleWrite(_HexToString($FileEdit)&@CRLF) Edited July 29, 2009 by BuckMaster
Malkey Posted July 29, 2009 Posted July 29, 2009 (edited) On 7/29/2009 at 5:27 AM, 'jebus495 said: #include <file.au3> #include <Array.au3> $lines = _FileCountLines("prepatch.log") $x2 = 1 For $x2 = 1 To $lines $linestring = FileReadLine("prepatch.log", $x2) $split = StringSplit($linestring, " ") For $x = 1 to $split[0] _FileWriteToLine("wordlist2.txt",$x2, $split[$x], 1) Next Next The above will read a text file and put every word on a separate line. It also creates a lot of blank lines in the process so now I need a way to remove blank lines or prevent them in the first place. Dim $aLines Dim $sFile = "wordlist2.txt" _FileReadToArray($sFile, $aLines) _ArrayDelete($aLines,4) FileDelete($sFile) For $i=1 to $aLines[0] If $aLines[$i]<>"" Then FileWriteLine($sFile,$aLines[$i]) Next I found this from searching but I can't seem to get it to work properly... This appears to work. ; #include <file.au3> #include <array.au3> Local $sFileOut = "wordlist2.txt" Local $hFileOut = FileOpen($sFileOut, 9) Local $sFile = "C:\PROGRA~1\AutoIt3\au3check.dat" Local $sREResult = StringRegExp(FileRead($sFile), "\S+(?= |\v+|$)", 3) ; returns array of every word ;_ArrayDisplay($sREResult) For $x = 0 To UBound($sREResult) - 1 FileWriteLine($sFileOut, $sREResult[$x] & @CRLF) Next FileClose($hFileOut) ShellExecute($sFileOut) ; This is faster. ; #include <file.au3> #include <array.au3> Local $sFileOut = "wordlist2.txt" Local $hFileOut = FileOpen($sFileOut, 10) Local $sFile = "C:\PROGRA~1\AutoIt3\au3check.dat" Local $sREResult = StringRegExpReplace(FileRead($sFile), "(\S+)(\s*|\v+|$)", "\1" & @CRLF) ; returns string of every word to a line. ;ConsoleWrite($sREResult & @CRLF) FileWrite($sFileOut, $sREResult) FileClose($hFileOut) ShellExecute($sFileOut) ; Edited July 29, 2009 by Malkey
jebus495 Posted July 29, 2009 Author Posted July 29, 2009 Thank you Malkey! That is much better than what I had lol.
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