The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 10-29-2008
majormark majormark is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 35
AWK to skip comments in XML file

Hello,

I'm trying to make a shell script to skip comments from an XML file, but with the code below only deletes comments that are in one line.

Can you tell me what can be added here?

Code:
nawk '

{
if($0 !~/<!--/) { a=0 } 

if($0 ~/<!--/ && $0 ~/-->/) {a=1} 

if($0 ~/<!--/) {a=1} 

if (a == 1) {next} 

if ($0 ~/-->/) {next} 

if (a == 0) {print $a} 
}

' ff
The file is:
Code:
this is a file
<!-- lalala  lalaa 1223
zzz
-->
begin here
important text here
<!-- 34543645 dsgs 1223
-->
important text here2
And the output is:
Code:
this is a file
zzz
begin here                                    
important text here
important text here2
As you can see the line "zzz" should not be printed.

Thanks