Jump to content
Sign in to follow this  

Replace all of line after specified string?

Recommended Posts


I understand how to use StringReplace for simple replacements, but I would be grateful for any help in solving this problem.

I want to search a file for a line that begins


and replace everything to the RIGHT of the equals sign with the contents of a variable.

I think I need to use a regular expression search to find the string between "Options=" and the CR/LF at the end of the line and then replace that string or the whole line. But I can't figure out the exact technique.

Thanks for any help with this.

Share this post

Link to post
Share on other sites


For every element in that array:

If StringLeft($array[$i], 7) = "Output=" Then
 $array[$i] = "Output="&$myVar

Once this is done, use _FileWriteFromArray to have the new content saved to a new file.

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post

Link to post
Share on other sites

$sStr = FileRead("Somefile,txt")
$sVar = "Some Replacement String"
$sStr = StringRegExpReplace($sStr, "(?m:^)(?i)(.*output=).+", "$1" & $sVar)


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: - 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

Both of those solutions are perfect, and it would have been a very long time before I thought of either of them on my own. Many thanks to you both!

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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.