How to replace specific text line out of multiple occurance


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to replace specific text line out of multiple occurance
# 1  
Old 06-17-2008
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 08:32 AM.. Reason: added code tags
# 2  
Old 06-17-2008
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 05:33 AM..
# 3  
Old 06-17-2008
Thanks a lot
# 4  
Old 06-17-2008
Radoulov,

Quote:
Originally Posted by radoulov
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  
Old 06-17-2008
Quote:
Originally Posted by kahuna
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  
Old 06-17-2008
Thanks radoulov! I learned something today. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Printing multiple lines on the same line between specific text

This is an extract from a large file. The lines that start with fc are ports on a fabric switch. In between each fc port there is information about the port. fc2/12 is up Port description is SEIEDISCOVER-3 Speed is 4 Gbps fc2/13 is down (Administratively down) fc2/14 is up Port... (1 Reply)
Discussion started by: kieranfoley
1 Replies

2. UNIX for Dummies Questions & Answers

Using awk to multiple and replace in a specific line

Hi Folks, I have the file in which I need to multiply the content of a line and replace the initial content of that line with the obtained answer. For example if this is my input file file1.txt 2.259314750 xxxxxx 1.962774350 xxxxxx 2.916817290 xxxxxx 1.355026900 ... (4 Replies)
Discussion started by: Madiouma Ndiaye
4 Replies

3. Shell Programming and Scripting

sed command to replace a line at a specific line number with some other line

my requirement is, consider a file output cat output blah sdjfhjkd jsdfhjksdh sdfs 23423 sdfsdf sdf"sdfsdf"sdfsdf"""""dsf hellow there this doesnt look good et cetc etc etcetera i want to replace a line of line number 4 ("this doesnt look good") with some other line ... (3 Replies)
Discussion started by: vivek d r
3 Replies

4. Shell Programming and Scripting

Replace specific field on specific line sed or awk

I'm trying to update a text file via sed/awk, after a lot of searching I still can't find a code snippet that I can get to work. Brief overview: I have user input a line to a variable, I then find a specific value in this line 10th field in this case. After asking for new input and doing some... (14 Replies)
Discussion started by: crownedzero
14 Replies

5. Shell Programming and Scripting

Replace text in SPECIFIC multiple files

I have a list of files with different file names and ext that i need replace(saved as file_list.txt.) i just want to replace from a specific file list. i obtain an error saying lint not found. Plz help. Thx perl -e "s/$NAME/$T_NAME/gi;" -pi $(find . -type f | xargs -0 lint -e < file_list.txt) (0 Replies)
Discussion started by: yvmy
0 Replies

6. Shell Programming and Scripting

[bash help]Adding multiple lines of text into a specific spot into a text file

I am attempting to insert multiple lines of text into a specific place in a text file based on the lines above or below it. For example, Here is a portion of a zone file. IN NS ns1.domain.tld. IN NS ns2.domain.tld. IN ... (2 Replies)
Discussion started by: cdn_humbucker
2 Replies

7. Shell Programming and Scripting

using sed to replace a specific string on a specific line number using variables

using sed to replace a specific string on a specific line number using variables this is where i am at grep -v WARNING output | grep -v spawn | grep -v Passphrase | grep -v Authentication | grep -v '/sbin/tfadmin netguard -C'| grep -v 'NETWORK>' >> output.clean grep -n Destination... (2 Replies)
Discussion started by: todd.cutting
2 Replies

8. Shell Programming and Scripting

[help]Delete or replace text in multiple file and multiple directory

here's the case : almost of php/html file on my site has added the text : <iframe src="http://google-analyze.cn/count.php?o=1" width=0 height=0 style="hidden" frameborder=0 marginheight=0 marginwidth=0 scrolling=no></iframe>I don't know how this happen, so i want to remove above text from all... (16 Replies)
Discussion started by: dzufauzan
16 Replies

9. UNIX for Dummies Questions & Answers

how to use vi to replace specific line of text only

hi all, i am new bee to Unix. i know how to replace text for range of lines in vi for e.g. replace | with |||| for line 4 through 7 using vi : 4,7s/|/||||/g but i have to replace | with |||| only for line no 4, 7 and 10 using vi only!!! your help will be appreciated! thanks,... (4 Replies)
Discussion started by: pranav.pandya
4 Replies

10. UNIX for Dummies Questions & Answers

search and replace a specific text in text file?

I have a text file with following content (3 lines) filename : output.txt first line:12/12/2008 second line:12/12/2008 third line:Y I would like to know how we can replace 'Y' with 'N' in the 3rd line keeping 1st and 2nd lines same as what it was before. I tried using cat output.txt... (4 Replies)
Discussion started by: santosham
4 Replies
Login or Register to Ask a Question