Your solution reveals the order number only...but my query is if the order number is there in the file corresponding <NJCustomer> & </NJCustomer> needs to be printed
Its the same thing...actually the perl code given by bartus works fine...but an if just looking for an awk solution(since the non-availability of the perl in the current environment).
awk '/<NJCustomer>/ , /<\/NJCustomer>/ # We are taking text from input xml which is between these two tags.
{if($0~/<OrderNumber>'$ord'<\/OrderNumber>/) # If any of the text(which we filtered in previous statement) match the string "<OrderNumber>'$ord'<\/OrderNumber>" ($ord is your order number) then
{print str;print $0;flg=1;next} # print str(i.e text prior to string "<OrderNumber>'$ord'<\/OrderNumber>" and current line i.e. "<OrderNumber>'$ord'<\/OrderNumber>"
else{str=str"\n"$0} # here we are taking prior text.
if(flg==1)
{if(/<NJCustomer>/) {str="";flg=0} #if my current record is /<NJCustomer>/ means start of new section then reset the "str" make flag zero.
else{print}}}' # if my flag is one then print the current record .i.e. text after string "<OrderNumber>'$ord'<\/OrderNumber>"