get rid of xml comment by grep or sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting get rid of xml comment by grep or sed
# 1  
Old 05-21-2009
Question get rid of xml comment by grep or sed

Hi,

I would like to get rid of all comment in an xml file by grep or sed command:
The content seem like this:

<!-- ab cd
ef gh
ij kl -->

Anyone can help?

Thanks and Regards
# 2  
Old 05-21-2009
this will delete that part
Code:
sed '/<!--/,/-->/d' filename

# 3  
Old 05-22-2009
it works!!
thank you very much!!
# 4  
Old 05-22-2009
perl:
Code:
undef $/;
my $str=<DATA>;
$str=~s/<!--.*?>\n//gs;
print $str;
__DATA__
<!-- ab cd 
ef gh
ij kl -->
line 1
<!-- ab cd 
ef gh
ij kl -->
line 2

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Getting string from xml tags using sed and grep

how to get string from tags using sed and grep i try to capture the tags : <groupId>org.test.proj.assent</groupId> <artifactId>mainapp</artifactId> <version>mainapp.1.4</version> <packaging>pom</packaging> <name>main app 1</name> and then from there i guess i will... (7 Replies)
Discussion started by: umen
7 Replies

2. UNIX for Beginners Questions & Answers

How to fetch the value from a xml using sed, GREP?

I have a simple xml file,need the output with the <value> tag and <result> tag text.xml <test-method status="FAIL" duration="45"> <value> Id=C18 </value> <result> wrong paramter </result> </test-method> <test-method status="FAIL" duration="45"> <value> Id=C19 </value> <result> Data... (5 Replies)
Discussion started by: DevAakash
5 Replies

3. Shell Programming and Scripting

sed to get rid of unwanted characters

so i have strings such as this: 'postfix/local#2,5#|CRON.*12062.*root.*CMD#2,5#|roice.*NQN1#1,2#|toysprc#1,4#' i need to get rid of the "#" and the numbers between them for each of the strings above. so the desired output should be: ... (1 Reply)
Discussion started by: SkySmart
1 Replies

4. Shell Programming and Scripting

Replacing part of XML code inside comment tags

Hello! I'd like to modify custom values in a XML config file between comment tags using bash script. <feature> <keyboardshortcut>C-m</keyboardshortcut> <option1>disabled</option2> <option2>enabled</option2> </feature> <!-- bash script features START --> <feature> ... (2 Replies)
Discussion started by: prism1
2 Replies

5. Shell Programming and Scripting

comment/uncomment grep output

Hi I need help to comment/uncomment the output from grep command output within a file from command line using shell script. # grep -i -p testfs filesystem.out /TestFs: dev = /dev/TestFslv vfs = jfs2 log = /dev/hd8 mount ... (2 Replies)
Discussion started by: mbak
2 Replies

6. Shell Programming and Scripting

Script to put block comment after finding regex in xml file

hi, i need my bash script to find regex in xml file.. and comment 2 lines before and after the line that contains regex.. can't use # needs to be <!-- at the beginning and --> and the end of the comment. so eg.. first block <filter> <filter-name>MyRegEx</filter-name> ... (11 Replies)
Discussion started by: Poki
11 Replies

7. Shell Programming and Scripting

Comment a line with SED

I have around 25 hosts and each hosts has 4 instance of jboss and 4 different ip attached to it . I need to make some changes to the startup scripts. Any tips appreciated. I have total of 100 instances which bind to 100 different ip address based on instance name. For example File1 ... (1 Reply)
Discussion started by: gubbu
1 Replies

8. Shell Programming and Scripting

Help using SED to comment XML elements

I'm trying to write a script to help automate some VERY tedious manual tasks. I have groups of fairly large XML files (~3mb+) that I need to edit. I need to look through the files and parse the XML looking for a certain flag contained in a field. If I find this flag (an integer value) I need... (4 Replies)
Discussion started by: J-Hon
4 Replies

9. Shell Programming and Scripting

using sed to get rid of duplicated columns...

I can not figure out this one, so I turn to unix.com for help, I have a file, in which there are some lines containing continuously duplicate columns, like the following adb abc abc asd adfj 123 123 123 345 234 444 444 444 444 444 23 and the output I want is adb abc asd adfj 123 345... (5 Replies)
Discussion started by: fedora
5 Replies

10. Shell Programming and Scripting

How to get rid of double quote in sed.

Hi, i am using sed command to grep just a valuable data for my report generating. Thanks to the person who assists me on before thread. the problem that i encounter now is when i executed below command The output will give me like below output in between the data, there is a double quote. How... (6 Replies)
Discussion started by: anakiar
6 Replies
Login or Register to Ask a Question