The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Replace text in multiple files on9west Shell Programming and Scripting 1 05-20-2008 01:35 AM
read space filled file and replace text at specific position COD Shell Programming and Scripting 6 04-21-2008 05:40 AM
Replace text in multiple files Tonka52 Shell Programming and Scripting 10 03-24-2008 08:11 AM
how to replace one line in text with several lines FunnyCats UNIX for Dummies Questions & Answers 1 01-18-2007 09:52 AM
jumping to a specific line in a text file mridula High Level Programming 4 09-20-2005 01:49 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-17-2008
madhusmita madhusmita is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 29
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:
Code:
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

Last edited by Yogesh Sawant; 06-17-2008 at 07:32 AM.. Reason: added code tags
  #2 (permalink)  
Old 06-17-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,794
Code:
perl -i.bak -00 -pe's/(TASK sipsiproc.*?ExitAction = )NONE/$1FALSE/s' inputfile
or:

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

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

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

Last edited by radoulov; 06-17-2008 at 04:33 AM..
  #3 (permalink)  
Old 06-17-2008
madhusmita madhusmita is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 29
Thanks a lot
  #4 (permalink)  
Old 06-17-2008
kahuna's Avatar
kahuna kahuna is offline
Registered User
  
 

Join Date: Apr 2007
Posts: 149
Radoulov,

Quote:
Originally Posted by radoulov View Post
Code:
perl -i.bak -00 -pe's/ExitAction = NONE/ExitAction = FALSE/ if /^TASK sipsiproc/' inputfile
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" .
  #5 (permalink)  
Old 06-17-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,794
Quote:
Originally Posted by kahuna View Post
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:

Quote:
Switches include:

-0[octal/hexadecimal]
specifies the input record separator ($/) as an octal or hexadeci-
mal number. If there are no digits, the null character is the
separator.
[...]

The special value 00 will cause Perl to slurp files in paragraph
mode. The value 0777 will cause Perl to slurp files whole because
there is no legal byte with that value.
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".
  #6 (permalink)  
Old 06-17-2008
kahuna's Avatar
kahuna kahuna is offline
Registered User
  
 

Join Date: Apr 2007
Posts: 149
Thanks radoulov! I learned something today.
Sponsored Links
Closed Thread

Bookmarks

Tags
solaris

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 07:45 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0