Jump to content

Search for string in a big file (200MB) and replacing it


GreYFoX
 Share

Recommended Posts

Look in the helpfile.

StringReplace()

StringReplace ( "string", "searchstring" or start, "replacestring" [, count [, casesense]] )

and how does that help me to search inside the file say "ddddd.dat" ?? (200+MB)

Edited by GreYFoX
Link to comment
Share on other sites

StringReplace ( "string", "searchstring" or start, "replacestring" [, count [, casesense]] )

and how does that help me to search inside the file say "ddddd.dat" ?? (200+MB)

Read the entire file into a single string, then do StringReplace() or StringRegExpReplace(), then write the string back to a file.

:)

P.S. The File.au3 UDF has the _ReplaceStringInFile() function just for this.

:P

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

StringReplace ( "string", "searchstring" or start, "replacestring" [, count [, casesense]] )

and how does that help me to search inside the file say "ddddd.dat" ?? (200+MB)

$oString = StringReplace (FileRead("ddddd.dat")"searchstring", "replacestring")
$oFile = FileOpen("ddddd.dat", 2)
FileWrite($oFile, $oString)
FileClose($oFile)

Not tested

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Hi,

Whatever you do, this wll be slow unless it is at the end of the file; then you can fast read just the last 100 lines (or whatever), using "_APITailRW" in my signature; and replace fast too.

The APIwrite/replace will work fast anywhere in file if you make it the same length as the line its replacing (ie set appropriate parameter in the UDF)

Best, Randall

Link to comment
Share on other sites

$oString = StringReplace (FileRead("ddddd.dat")"searchstring", "replacestring")
$oFile = FileOpen("ddddd.dat", 2)
FileWrite($oFile, $oString)
FileClose($oFile)

Not tested

i mentioned the size of the file..... cause if u do that m8 u'll burn ur processor lol joke
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...