How to replace specific text line out of multiple occurance

Hi

I would like to replace specific line eg ExitAction = NONE to ExitAction = FALSE under only TASK sipsiproc and other ExitAction = NONE will remain as usual in the file(shell script)

The file contains:

TASK rgcdproc {
    CommandLine    = $SSHOME/bin/rgcd.exe
    NewConsole     = yes
    ExitAction     = NONE
    DependantProcs = megacopiproc
}

TASK sipsubsystemproc {
    CommandLine    = $SSHOME/bin/sipsubsystem.exe
    NewConsole     = yes
    ExitAction     = NONE
    DependantProcs = sipsiproc
}

TASK sipsiproc {
    CommandLine    = $SSHOME/bin/sip_si.exe
    NewConsole     = yes
    ExitAction     = NONE
    DependantProcs = sipsubsystemproc
}

TASK megacopiproc {
    CommandLine    = $SSHOME/bin/megacopi.exe
    NewConsole     = yes
    ExitAction     = NONE
    DependantProcs = rgcdproc

With regards,
Madhu

perl -i.bak -00 -pe's/(TASK sipsiproc.*?ExitAction = )NONE/$1FALSE/s' inputfile

or:

perl -i.bak -00 -pe's/ExitAction = NONE/ExitAction = FALSE/ if /^TASK sipsiproc/' inputfile

With Awk (nawk or /usr/xpg4/bin/awk on Solaris):

awk '/^TASK sipsiproc/{sub(/ExitAction = NONE/,"ExitAction = FLASE")}1' ORS="\n\n" RS= inputfile>newfile

Thanks a lot

Radoulov,

Could you explain a little more on how the second perl solution works? I can't figure out how the substitute knows which "ExitAction = NONE" to substitute. I see that you're qualifying it with the if statement, but I still don't see how that makes the substitute get right "ExitAction = NONE" and not the first "ExitAction = NONE" .

Sure,
the -00 flag+argument turns the paragraph mode on.
From perldoc perlrun:

In this mode each record is a paragraph of text terminated by one or more empty lines.
So change the ExitAction only for the record(s)/paragraph(s) that begin with the pattern "Task sipsiproc".

Thanks radoulov! I learned something today. :slight_smile: