我試圖從grep
兩行html
模式從文件中打印並使用cat
打印。的行是:如何在index.html文件中使用egrep匹配2行html代碼
<link type="text/css" rel="stylesheet" href="https://test.mydomain.com/store.css">
和
<script type="text/javascript" language="javascript" src="https://test.mydomain.com/store/gwt.nocache.js">
如果我使用他們seperatly使用grep
命令。像
if grep -F -i -n '<link type="text/css" rel="stylesheet" href="https://test.mydomain.com/store.css">' tmp.html > out.txt; then cat out.txt # IT WORKS.
但我需要grep
這兩種模式。我試着用egrep
。作爲
egrep '(pattern1|pattern2)'
爲
if egrep -e -i -c '(\<link type\=\"text\/css\" rel\=\"stylesheet\" href\=\"https\:\//test\.mydomain\.com\/gwtstore\/store\.css\"\>|\<link type\=\"text\/css\" rel\=\"stylesheet\" href\=\"https\:\//test\.mydomain\.com\/store\/gwt\.nocache\.js\"\>)' tmp.html > out.txt; then cat out.txt
,但上面的語法不工作了..請協助。我試着在文件中搜索兩組html代碼,如果它們退出,則使用sed
命令以另一種模式替換。
http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags – jordanm 2012-04-20 13:04:55
如果你想使用sed,你可以立即使用sed - 你爲什麼要使用grep呢? – 2012-04-20 13:46:52