我想通过我的所有的HTML文件到grep,看看我有什么不好的标签存在,例如<br>
,<hr>
等等,这是我希望看到的标签没有在HTML文件关闭。
for htmlFile in `ls -f *.html ` ; do
if `cat $htmlFile | grep -inE "\<br\>"` ; then
echo "In file $htmlFile there are errors on the following lines: " >> ~/Desktop/$1_errors.txt
cat $htmlFile | grep -in "<br>"| cut -d ":" -f1 >> ~/Desktop/$1_errors.txt
echo "----------------------------------------" >> ~/Desktop/$1_errors.txt
fi
done
但是我得到一个错误,我怀疑它是我的正则表达式。
./script.sh: line 14: 10:<BR: command not found
那是我得到的错误之一:)
您的问题在此行中:
if `cat $htmlFile | grep -inE "\<br\>"` ; then
它告诉shell:
<br>
标记匹配的行,问题是最后一步,您不应该执行命令的输出,而应该对其进行测试:
if grep -inEq "\<br\>" $htmlFile ; then
当然,要解析HTML,您应该使用真正的解析器,而不要使用正则表达式。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句