Link to home
Start Free TrialLog in
Avatar of IanPaskin
IanPaskin

asked on

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

ASKER CERTIFIED SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of IanPaskin
IanPaskin

ASKER

Perfect thanks, works a treat.