awk script xml file remove nodes

I have an XML file that i need to post process and need to remove certain lines/nodes in the file in this example i want t remove all nodes that have the word 'confirmation' in the node name,

Example XML and what i have tried below.

I open the file and readin the contens then output
Source XML File

<ShipNoticeItem lineNumber="20" quantity="8">
 <ConfirmationStatus type="reject" quantity="0">
 <UnitOfMeasure>PACK</UnitOfMeasure>
 </ConfirmationStatus>
</ShipNoticeItem>
<ConfirmationItem lineNumber="30" quantity="0">
 <ConfirmationStatus type="reject" quantity="0">
 <UnitOfMeasure>PACK</UnitOfMeasure>
 </ConfirmationStatus>
</ConfirmationItem>

cat $MyFile | awk -F "<" 'BEGIN {
  TRUE=1;
  FALSE=0;
 }

	{
	if ( length($0)==0 )
	continue;
		
         if ( substr($2,1,4) !="Conf") 
	  {
	  print $0;
	  continue;	
	}	
			
						
	if ( substr($2,2,4) !="Conf")
	{
	print $0;
	continue;
	}

 }' > /tmp/outputfile.xml

Open in new window

IanPaskinAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
woolmilkporcConnect With a Mentor Commented:
awk -F "<" 'BEGIN {
  TRUE=1;
  FALSE=0;
 }
        {
        if ( length($0)==0 )
        continue;
               
         if ( substr($2,1,4)=="Conf")
          {
         continue;    
          }      
                       
                                               
        if ( substr($2,2,4)=="Conf")
         {
        continue;
        }
         {
         print;
        }
 }' $MyFile  > /tmp/outputfile.xml

wmp
0
 
IanPaskinAuthor Commented:
Perfect thanks, works a treat.
0
All Courses

From novice to tech pro — start learning today.