2012-12-08 54 views
0

我有一個HTML創建腳本,並在其中我試圖:查找HTML字符串和備註

1)更換RelatedLinksBlock的所有實例使用SED
2.多行DOS變量)查找一個是匹配的DOS變量和REM出來或使用SED

我不能讓任何SED命令幾個小時後,開始工作,需要一些幫助刪除字符串。

CODE:

SETLOCAL ENABLEEXTENSIONS 
SETLOCAL ENABLEDELAYEDEXPANSION 
set nl=^& echo. 
set fullHTMLpath=http://this.com 
set FileTitle=Computer TEST 
set keyfile=test.html 
set rempath=REMthisOUT 
set "delpath=^<li^> - ^<a href="%fullHTMLpath%" title="%FileTitle%"^>%FileTitle%^</a^>^</li^>" 
set "path1=^<li^> - ^<a href="http://that.com/computers-and-operating-systems/asus-computer-support.html" title="ASUS Computer Support"^>ASUS Computer Support^</a^>^</li^>" 
set "path2=^<li^> - ^<a href="http://that.com/computers-and-operating-systems/asus-laptop-support.html" title="ASUS Laptop Support"^>ASUS Laptop Support^</a^>^</li^>" 
set "path3=^<li^> - ^<a href="http://that.com/computers-and-operating-systems/asus-support.html" title="ASUS Support"^>ASUS Support^</a^>^</li^>" 
set alllinks=%path1%%nl%%path2%%nl%%path3% 

sed -i "s/RelatedLinksBlock/%alllinks%/g" "%keyfile%" 
sed -i "s/%delpath%/%rempath%/g" "%keyfile%" 

謝謝

回答

0

如果我知道的sed處理換行符,而不是批處理文件SED正確,換行應該是\ N;並且字符串中的正斜槓需要通過反斜槓進行轉義。無論何時從字面上使用字符\\ &,他們都需要被轉義。也沒有什麼利用你的代碼片段中的延遲擴展,所以我刪除了它。

SETLOCAL ENABLEEXTENSIONS 
set "fullHTMLpath=http:\/\/this.com" 
set "FileTitle=Computer TEST" 
set "keyfile=test.html" 
set "rempath=REMthisOUT" 
set "delpath=^<li^> - ^<a href="%fullHTMLpath%" title="%FileTitle%"^>%FileTitle%^<\/a^>^<\/li^>" 
set "path1=^<li^> - ^<a href="http:\/\/that.com\/computers-and-operating-systems\/asus-computer-support.html" title="ASUS Computer Support"^>ASUS Computer Support^<\/a^>^<\/li^>" 
set "path2=^<li^> - ^<a href="http:\/\/that.com\/computers-and-operating-systems\/asus-laptop-support.html" title="ASUS Laptop Support"^>ASUS Laptop Support^<\/a^>^<\/li^>" 
set "path3=^<li^> - ^<a href="http:\/\/that.com\/computers-and-operating-systems\/asus-support.html" title="ASUS Support"^>ASUS Support^<\/a^>^<\/li^>" 
set "alllinks=%path1%\n%path2%\n%path3%" 

sed -i "s/RelatedLinksBlock/%alllinks%/g" "%keyfile%" 
sed -i "s/%delpath%/%rempath%/g" "%keyfile%" 

除了那些現在的建議,你是否收到任何錯誤信息,你可以告訴我們?