Sign in to follow this  
Followers 0
GreYFoX

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

8 posts in this topic

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

i'm searching for a string inside a file and trying to replace it but i can't seem to find a way to put it in code pls help

Share this post


Link to post
Share on other sites



Look in the helpfile.

StringReplace()

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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

Share this post


Link to post
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!"

Share this post


Link to post
Share on other sites

hi

i assume the file itself is ascii code

then read the file line by line, and try to find the string- if you do: replace,

write the lines ( replaced or not ) to outfile..

greets nobbe

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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
Sign in to follow this  
Followers 0