Script to put block comment after finding regex in xml file
hi,
i need my bash script to find regex in xml file.. and comment 2 lines before and after the line that contains regex.. can't use # needs to be <!-- at the beginning and --> and the end of the comment.
so eg..
so output should be
unfortunately since it's an xml file.. # is not funtioning..
obviously there is no problem to find regex.. .. i can also find the lines of regex.. the difficulty is to wrap around 2 lines before and after.. with <!-- and -->
Does anyone know how to do it? i have been working on it for quite some time now..
Thank you
Last edited by Scott; 01-11-2011 at 04:26 PM..
Reason: Please use code tags
You want to comments out lines, try sed, using N to get the entire element in /<\([^ >]*\).*<\/\1>/, and then wrap it in comment markup s/.*/<!-- & -->/ or similar.
You want to comments out lines, try sed, using N to get the entire element in /<\([^ >]*\).*<\/\1>/, and then wrap it in comment markup s/.*/<!-- & -->/ or similar.
what do you mean by ?
"using N to get the entire element in /<\([^ >]*\).*<\/\1>/, "
Using sed N to get an entire element. Let's say the element name is MsgBlk:
Narrative:
Find the line with the opening element, and on it:
Set a branch target named loop.
If the element is not closed:
If at EOF, it is junk, delete it. Some sed are funny wih N at EOF.
Pile the next line at the end of the buffer.
Go back to check fo close of element.
Pick up just exactly this whole element, and where its ends were, put commenting markup and new lines around the while element.
Using sed N to get an entire element. Let's say the element name is MsgBlk:
Narrative:
Find the line with the opening element, and on it:
Set a branch target named loop.
If the element is not closed:
If at EOF, it is junk, delete it. Some sed are funny wih N at EOF.
Pile the next line at the end of the buffer.
Go back to check fo close of element.
Pick up just exactly this whole element, and where its ends were, put commenting markup and new lines around the while element.
i ran it like you have specified the output hasn't changed at all.. (substituted MsgBlk with my regex)
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)
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)
(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)
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)
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)
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)
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)
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)
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)