So that when I fetch the PARTDESC node value it should return me one line value with '&' replaced.
Any help in this will be appreciated.
I can help, but I won't have access to a Unix/Linux machine to test this. As such, we can take this discussion off line if you need to be my eyes and fingers to get through it.
So, it sounds like you want to append lines to the <PARTDESC> tag until the closing tag is encountered. Simple enough... I'm going to be using the pattern space and hold space to do this, so a combination of the sed commands g,G,h,H,x, etc. will be used. A point to take note of is when appending a line to the hold space, the CR/NL needs to be removed. I have a trick for that too.
As a quick review, the pattern space is a buffer that sed uses to read a line of input. The hold space is a buffer that is for the user. The pattern space is where string parsing is done. The hold space is just a buffer and cannot be directly modified.
Ok, here we go. First, we'll clear the hold space when the first line of input is read. This is probably not necessary, but carried on by me when you're supposed to clear a memory buffer after allocating it.
Next, we'll start reading the input lines until the opening tag is found. We'll copy the pattern space to the hold space. We'll leave the CR/NL that also goes into the hold space for now.
We'll continue reading lines until the closing tag is found. While doing this, we'll swap the pattern space and the hold space to remove the CR/NL from the appended string we're creating. Then, we'll put the pattern space back to the hold space to do the same thing for the next line.
When the closing tag is found, output the hold space, then output the closing tag. Note that this assumes the opening and closing tags start at the beginning of a line and the closing tag is on a line by itself. It also assumes that there is a closing tag for every opening tag. It's possible to handle these situations if not, but I've got other things to do today . Repeat these steps from the beginning by initializing the hold space and start looking for the next opening tag (or EOF).
Now the sed script:
Give that a shot and let me know how it goes. Sorry, I can't test it, but if you understand sed basics, you should be able to spot syntax and typo issues.