I want to build a script that can grab certain paramethers out of the xml-like tags. It is hard to explain without an example so, let me start with an example.
Let's say I have a file called xyz.html that contains:
<html>
<head>
<title>xyz</title>
<head>
<body>
<img src="\home\pics\1.gif">
<!-- <img src="\home\pics\2.gif">
<img src="\home\pics\3.gif">
<img src="\home\pics\4.gif">
<img src="\home\pics\5.gif"> -->
<img src="6.gif">
<!-- <img src="\home\pics\7.gif"> -->
</body>
</html>
Now I want to extract all the images that are within the comment tags (<!-- -->), in this case they'll be 2.gif, 3.gif, 4.gif, 5.gif and 7.gif. By using grep expression (such as : grep "<!--(.*)-->" *.*), I can easily extract 7.gif, but extracting images out of the commented block is a challenge. So is there a way to do this with grep or any other utilities?
Question
neomodus
Hi,
I want to build a script that can grab certain paramethers out of the xml-like tags. It is hard to explain without an example so, let me start with an example.
Let's say I have a file called xyz.html that contains:
<html>
<head>
<title>xyz</title>
<head>
<body>
<img src="\home\pics\1.gif">
<!-- <img src="\home\pics\2.gif">
<img src="\home\pics\3.gif">
<img src="\home\pics\4.gif">
<img src="\home\pics\5.gif"> -->
<img src="6.gif">
<!-- <img src="\home\pics\7.gif"> -->
</body>
</html>
Now I want to extract all the images that are within the comment tags (<!-- -->), in this case they'll be 2.gif, 3.gif, 4.gif, 5.gif and 7.gif. By using grep expression (such as : grep "<!--(.*)-->" *.*), I can easily extract 7.gif, but extracting images out of the commented block is a challenge. So is there a way to do this with grep or any other utilities?
Thanks,
neomodus.
Link to comment
Share on other sites
2 answers to this question
Recommended Posts