leuce Posted September 16, 2007 Posted September 16, 2007 G'day everyoneI have hundreds of text files with superfluous blank lines and double spaces in them. I'd like to replace all double spaces with a single space (this may require several passes) and all double blank lines with a single blank line (again, several passes may be necessary). How would I do this?This doesn't work:$foo = FileOpen ("foo.txt", 128) StringReplace ($foo, @CRLF & @CRLF, @CRLF) FileClose ($foo)I suppose I could do FileReadLine + SomeRegularExpression + FileWriteLine on every line of every file, but I suspect that is going to take a long, long time. I could also have the script open each file in Notepad (or Notepad++), perform the operation via the text editor, and save again, but then I can't do all of this in the background.Is there any other way to perform such a whole-file operation?ThanksSamuel
leuce Posted September 16, 2007 Author Posted September 16, 2007 I have hundreds of text files with superfluous blank lines and double spaces in them. I'd like to replace all double spaces with a single space (this may require several passes) and all double blank lines with a single blank line (again, several passes may be necessary). How would I do this? Hmm, the AutoIt help file says "FileWrite" only writes a single line, and I guess that comment did it for me. But if you think about it... a single line that contains several hard returns is still a single line :-) This does work: $foo = FileOpen ("foo.txt", 128) $bar = FileRead ($foo) $content = StringReplace ($bar, @CRLF & @CRLF, @CRLF) FileClose ($foo) $foo2 = FileOpen ("foo.txt", 130) FileWrite ($foo2, $content) FileClose ($foo2)oÝ÷ Ø âqëh¹Èfk&Þ¶u§ÞÂX§zËajÙæiÉ.¥Ê)Êߢq¶ØhºZºÚ"µÍÌÍÙ[HH ][ÝÙÛË ][ÝÂÌÍÙÛÈH[SÜ[ ÌÍÙ[KL BÌÍØH[TXY ÌÍÙÛÊBÌÍÙÛØXÚÈH[SÜ[ ÌÍÙ[H [È ][ÝרXÚÝ ][ÝËLÌ B[UÜ]H ÌÍÙÛØXÚË ÌÍØBÌÍØÛÛ[HÝ[ÔXÙH ÌÍØÔ [ÈÔÔB[PÛÜÙH ÌÍÙÛÊBÌÍÙÛÌH[SÜ[ ][ÝÙÛË ][ÝËLÌ B[UÜ]H ÌÍÙÛÌ ÌÍØÛÛ[ B[PÛÜÙH ÌÍÙÛÌ
DjDeep00 Posted September 16, 2007 Posted September 16, 2007 1. Read all the file names into an array by using "_FilelisttoArray" 2. Create a loop to go thru all of the files one by one and then use "_Filereadtoarray" 3. Create another loop to replace all the spaces and carriage returns in the file. 4. Write the new lines to a new file.
Gordon J. Tyler Posted September 17, 2007 Posted September 17, 2007 The StringStripWS() function has an option to strip out double whitespace characters It considers a bunch of stuff white space include @CR and @LF and spaces
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