如何使用grep,sed或awk等shell命令提取以下脚本标签中的内容?
<script>
document.getElementById("p1").innerHTML = "API Dev :: UP";
document.getElementById("p2").innerHTML = "API QA :: UP";
document.getElementById("p3").innerHTML = "API Regression :: UP";
document.getElementById("p4").innerHTML = "API Pre-Prod :: UP";
</script>
-Thanks
答案 0 :(得分:0)
根据您的描述:
sed '/script/d' sample.csv
使用/script/
匹配包含字符串script
的行,而d
则删除这些行。
或者,使用grep "document.getElementById" sample.csv
。使用grep匹配模式
输出:
document.getElementById("p1").innerHTML = "API Dev :: UP";
document.getElementById("p2").innerHTML = "API QA :: UP";
document.getElementById("p3").innerHTML = "API Regression :: UP";
document.getElementById("p4").innerHTML = "API Pre-Prod :: UP";
答案 1 :(得分:0)
其他一些替代方案
$ grep -Ev '</?script>' file
或
$ gawk -v RS='</?script>' '!(NR%2)' file