Sponsored Content
Top Forums Shell Programming and Scripting Script to put block comment after finding regex in xml file Post 302487138 by Poki on Tuesday 11th of January 2011 02:12:14 PM
Old 01-11-2011
Quote:
Originally Posted by rdcwayx
Code:
awk '/<filter>/||/<filter-mapping>/ {print "<!--\n" $0;next} 
     /<\/filter>/||/<\/filter-mapping>/ {print $0 "\n-->";next}1 ' infile


thanks .. but i have lots of sections that look like this.. i only need to comment section that has MyRegEx
Code:
    <filter>
        <filter-name>something</filter-name>
        <filter-class>something</filter-class>
        <init-param>
            <param-name>filterKey</param-name>
            <param-value>remote</param-value>
        </init-param>
    </filter>
     
   
    <filter>
        <filter-name>MyRegEx</filter-name>
        <filter-class>MyRegExblabla</filter-class>
    </filter>


    <filter>
        <filter-name>something</filter-name>
        <filter-class>somethingelse</filter-class>
        <init-param>

            <param-name>filterKey</param-name>
            <param-value>something</param-value>
        </init-param>
    </filter>

        <filter-mapping>
            <filter-name>something</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>

    <filter-mapping>
        <filter-name>something</filter-name>
        <url-pattern>/servlet/something</url-pattern>
        <url-pattern>/servlet/something</url-pattern>
        <url-pattern>/servlet/something</url-pattern>
        <url-pattern>/servlet/something</url-pattern>
        <url-pattern>/servlet/something</url-pattern>
    </filter-mapping>


    <filter-mapping>
        <filter-name>something</filter-name>
        <url-pattern>/remote/*</url-pattern>
    </filter-mapping>


    <filter-mapping>
        <filter-name>something</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>


    <filter-mapping>
        <filter-name>MyRegEx</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

Moderator's Comments:
Mod Comment Please use code tags

Last edited by Scott; 01-11-2011 at 03:27 PM.. Reason: Code tags, please...
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Block Comment in Shell script

how to put multiline comments in a shell script like /* Some code */ in C language? (3 Replies)
Discussion started by: skyineyes
3 Replies

2. Shell Programming and Scripting

How to put a comment at the begining of the sentence

I have a file shows as below. I would like to put # before CCCC. so how to do in Solaris. Here sed doesnot support -i AAAA BBBB CCCCC DDDDD EEEEE FFFFFF (1 Reply)
Discussion started by: madhusmita
1 Replies

3. Shell Programming and Scripting

Finding a XML element and moving the file

Hi All, I am looking for a awk/shell which can find an element named REFERENCE in a XML file and check whether it is empty or not. If there is no value in the REFERENCE element then correspondingly move the file to some other folder. The Unix server is AIX version 4. Any inputs... (9 Replies)
Discussion started by: karansachdeva
9 Replies

4. Shell Programming and Scripting

get rid of xml comment by grep or sed

Hi, I would like to get rid of all comment in an xml file by grep or sed command: The content seem like this: <!-- ab cd ef gh ij kl --> Anyone can help? Thanks and Regards (3 Replies)
Discussion started by: RonLii
3 Replies

5. Shell Programming and Scripting

Help using SED to comment XML elements

I'm trying to write a script to help automate some VERY tedious manual tasks. I have groups of fairly large XML files (~3mb+) that I need to edit. I need to look through the files and parse the XML looking for a certain flag contained in a field. If I find this flag (an integer value) I need... (4 Replies)
Discussion started by: J-Hon
4 Replies

6. Shell Programming and Scripting

regex/shell script to Parse through XML Records

Hi All, I have been working on something that doesn't seem to have a clear regex solution and I just wanted to run it by everyone to see if I could get some insight into the method of solving this problem. I have a flat text file that contains billing records for users, however the records... (5 Replies)
Discussion started by: Jerrad
5 Replies

7. Shell Programming and Scripting

search a word in a xml file and print the out put

hi , i m having a html file and this file looks like this <ssl> <name>PIA</name> <enabled>true</enabled> <listen-port>39370</listen-port> </ssl> <log> <name>PIA</name> </log> <execute-queue> <name>weblogic.kernel.Default</name> ... (7 Replies)
Discussion started by: becksram123
7 Replies

8. Shell Programming and Scripting

finding a block in a file and replace with another file block.

(1) Yes but how is this block different from the other 24? You will need this information in order to identify and replace this block correctly (out of the 25). Ans: The 1st line and last line of this block are unique from other block. The 1st line is “rem Subset Rows (&&tempName.*) and The... (1 Reply)
Discussion started by: Zaheer.mic
1 Replies

9. Shell Programming and Scripting

Replacing part of XML code inside comment tags

Hello! I'd like to modify custom values in a XML config file between comment tags using bash script. <feature> <keyboardshortcut>C-m</keyboardshortcut> <option1>disabled</option2> <option2>enabled</option2> </feature> <!-- bash script features START --> <feature> ... (2 Replies)
Discussion started by: prism1
2 Replies

10. Shell Programming and Scripting

Using :<<cut / cut to comment out block of bash script

I am using : << cut / cut to comment out block of code. Works fine on few lines of script, then it gives me this cryptic error when I try to comment out about 80 lines. The "warning " is at last line of script. done < results 169 echo "END read all positioning parameters" 170... (8 Replies)
Discussion started by: annacreek
8 Replies
All times are GMT -4. The time now is 05:59 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy