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



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Add Comments to the specifi lines i na file ukatru UNIX for Advanced & Expert Users 1 09-21-2008 08:39 AM
removing comments from file skully Shell Programming and Scripting 9 06-08-2008 09:44 PM
skip reading certain lines in a file paulsew UNIX for Dummies Questions & Answers 5 03-26-2007 03:07 AM
Skip new line pmpx Shell Programming and Scripting 2 10-13-2005 12:43 AM
FreeBSD skip UserConfig... Enoch Chan BSD 2 09-03-2003 05:48 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #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
  #2 (permalink)  
Old 10-29-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,854
Code:
awk '/^<!--/,/^-->/{next}1' infile
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:41 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0