我已經試過這無數的方法,時間認輸,並要求主...sed的變量替換
#!/bin/bash
# Read in the VERSION.header file, this is a plain text file
# with returns, which in some of my tests, I am loosing the returns and getting
# one string wrapped only by the shell width
VERSION_HEADER=`cat VERSION.header`
sed 's/_VERSION_HEADER_/"$VERSION_HEADER"/g' DOCUMENTATION
字符串「_VERSION_HEADER_」作爲文件文檔線1當前存在。文件'VERSION.header'有大約18行。
我不會使用sed。我所要做的就是讀取一個作爲模板的文件,將該文件數據存儲爲變量,讀入第二個文件,將其存儲爲變量。在第二個文件中查找標記,用第一個文件中的數據替換標記。
例子:
$貓VERSION.header
hi, this is my header file, how are you today
good, that is nice, great
have a nice day, k, thx, bye.
$貓文檔
_VERSION_HEADER_
# This is a documentation file, please read it
# If you do not read it, you will get stuck to the toilet.
而且結果應該是:
嗨,這是我的頭文件,你今天好嗎
不錯,那很好,很棒
祝你有美好的一天,k,thx,再見。
#這是一個文檔文件,請閱讀它
#如果你沒有閱讀它,你會被卡在廁所裏。
你有什麼結果? – hudolejev 2010-06-19 11:14:12
[用變量(sed)替換文本](http:// stackoverflow。com/questions/16297052/replace-a-text-with-a-variable-sed) – tripleee 2013-08-30 09:32:42