The specific set of files in my case, are all included in a specified directory and its sub-directories. I need to make sure it does not delete conditional rules for IE browsers, like <!--[if IE 9]>
. Here is a sample dataset:
<!DOCTYPE html>
<!-- Should not delete the conditional below -->
<!--[if IE 9]>
<html>
<![endif]-->
<head></head>
<body>
<p>Some content</p>
<!--Single line without space-->
<!-- Single line with spaces -->
<!-- Multi
Line
Comment -->
<div>Content</div>
</body>
</html>
This will not handle more complex cases, but could get you started:
#!/usr/bin/awk -f
/<!--/ {comm = 1}
comm == 0
/-->/ {comm = 0}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.