How can i comment out a section between two particular lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How can i comment out a section between two particular lines
# 1  
Old 02-14-2012
How can i comment out a section between two particular lines

I want to find out which files under /etc have the the following section:

Quote:
<!------ BEGIN e-healthcare SETUP ------>
---- ---- ----- ----- ----
---- ---- ----- ----- ----
---- ----- ----- ---- ----
---- ----- ----- ---- ----
---- ----- ----- ---- ----
<!------ END e-healthcare OAS SETUP ------>
and then i would like to comment out the above section in all the files.
Please help.
# 2  
Old 02-14-2012
I am using the # character at the begining of the line. change it to reflect your idea of commenting out.
Code:
awk ' BEGIN{ ok=0 }
        /BEGIN e-healthcare SETUP/ {print $0; ok=1; next}
        / END e-healthcare OAS SETUP/ {ok=0}
        ok==1 {printf(" #")}
        {print $0}' somefile > newfile

       # only if this works for you
        mv newfile somefile

to find files (under /etc ? really weird)
Code:
grep -l ' END e-healthcare OAS SETUP' /etc/*

# 3  
Old 02-15-2012
Jim I like this.
# 4  
Old 02-15-2012
Or if you want to include the headers as well:
Code:
sed '/BEGIN e-healthcare SETUP/,/END e-healthcare OAS SETUP/{s/^/# /;}' infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Count lines in section

I am tiring to cont numbers of line between the "!" in CISCO routers I have no problem to extract the input and change the empty line with ! ! 5 Cable5/0/1 U0 4 5 Cable5/0/1 U1 4 ! 5 Cable5/0/1 U2 4 ... (4 Replies)
Discussion started by: sharong
4 Replies

2. Shell Programming and Scripting

Comment ( -- ) lines from 10 to 25 for every .sql file

Platform : RHEL 5.4 I have several .sql files in a directory. I want to comment lines 10 to 25 for all .sql files. How can I do this ? The symbol for comment in SQL is -- eg: -- select salary from emp where empname = 'URS' ; (3 Replies)
Discussion started by: omega3
3 Replies

3. UNIX for Dummies Questions & Answers

Comment lines in file without vi editor

Legends, Can you please help me in following. I need to comment lines from “/tmp/a.txt” from the line A to line B through the command prompt only. Please use variables not direct values like 2 or 5 It can be done with VI editor but it's not matches with my requirement (: 2,5 s/^/#/g). ... (1 Reply)
Discussion started by: sdosanjh
1 Replies

4. Shell Programming and Scripting

Adding a lines to specific section of the file.

Hello, I have to a add 2 lines to /etc/sudoers file under this section below, can someone please suggest script to add these two lines when execute this remotely on to a multiple servers. before ## Allow root to run any commands anywhere root ALL=(ALL) ALL After ## Allow root... (2 Replies)
Discussion started by: bobby320
2 Replies

5. Shell Programming and Scripting

using awk to get specific section of lines in logs

i have a log file that has the date and time that looks like this: Wed Jun 28 15:46:21 2012 test failed tailed passed passed not error panic what we want to focus on is the first 5 columns because they contain the date and time. the date and time can be anywhere on the line. in this... (6 Replies)
Discussion started by: SkySmart
6 Replies

6. Shell Programming and Scripting

Comment lines in FSTAB using perl

Hi All, I need to comment specific Two Lines in fstab & want to do using & also want to ensure that is done corretly. I am trying the below method. But its giving Search pattern not terminated. ################ b36376 67 % cat linux-fstab_testing | perl -i -wnl -e '/^('\Q... (1 Reply)
Discussion started by: ajaincv
1 Replies

7. Shell Programming and Scripting

how to add more number in comment section D0000,S0000,D0000,D12345,S12345 |

#!/bin/bash repository=$1; txn=$2; #echo -e "\n\npre-hook Script called\n\n"; logmsg=$(svnlook log ${repository} -t ${txn}); logmsg_vals="${logmsg%%|*}|"; logmsg_char="${logmsg_vals:0:1}"; logmsg_len=$(echo ${logmsg} | cut -d' ' -f1); # logmsg_len2=$(echo ${logmsg} | awk '{print... (1 Reply)
Discussion started by: anuragpgtgerman
1 Replies

8. Shell Programming and Scripting

Placing Duplicate Lines per section into another file

Hello, I need help in putting duplicate lines within a section into another file. Here is what I'm struggling with: Using this file “data.txt”: ABC1 012345 header ABC2 7890-000 ABC3 012345 Header Table ABC4 ABC5 593.0000 587.4800 ABC5 593.5000 587.6580 <= dup need to remove ABC5... (4 Replies)
Discussion started by: petersf
4 Replies

9. Shell Programming and Scripting

Removing Duplicate Lines per Section

Hello, I am in need of removing duplicate lines from within a file per section. File: ABC1 012345 header ABC2 7890-000 ABC3 012345 Header Table ABC4 ABC5 593.0000 587.4800 ABC5 593.5000 587.6580 <= dup need to remove ABC5 593.5000 ... (5 Replies)
Discussion started by: petersf
5 Replies

10. UNIX for Dummies Questions & Answers

comment lines

Is there a command to put a comment (#) in a whole part of a shell script? (5 Replies)
Discussion started by: vero_81
5 Replies
Login or Register to Ask a Question