如:
test.bat(內容如下)
set ID=123 ,
=============================
文字檔T.txt(部分內容如下)
.
ser=%ID%
.
=============================================
;T.txt引入環境變數後儲存成文字檔T.dat(部分內容如下)
.
ser=123
.
set ID=123 echo ser=%ID% > t.dat type t.dat
sed -e 's/%D%/123/g' T.txt > T.dat
C:\tmp>type T.txt ASDFGHJKL ser=%ID% WERTYUIKG test for other %ID% C:\tmp>sed -e "s/%ID%/123/" T.txt ASDFGHJKL ser=123 WERTYUIKG test for other 123 C:\tmp>sed -e "s/%ID%/123/" T.txt > T.dat
C:\tmp>sed -e "s/%ID%/123/;s/%NAME%/Peter/" T.txt ASDFGHJKL ser=123 WERTYUIKG test for other 123 my Name is Peter
s/%ID%/123/ s/%NAME%/Peter/
C:\tmp>sed -f script.txt T.txt
sed -f myscript.sed T.txt > T.dat
set ID=123 set NAME=Peter echo s/%%ID%%/%ID%/;s/%%NAME%%/%NAME%/ > myscript.sed call test2.bat
set ID=123 set NAME=Peter echo sed -e "s/%%ID%%/%ID%/;s/%%NAME%%/%NAME%/" T.txt > test2.bat call test2.bat
echo "%ser%" > t.dat
樓主的意思應該是這個內容是在文字檔中間某一行....
如果在 linux 上就簡單了...用 sed 就可以解決...
sed?在windows下也可以喔:
http://gnuwin32.sourceforge.net/
如果熟悉linux工具,想在windows環境下使用的話...