sed 帶變數 如何取代 特殊符號 - Linux

Table of Contents




如題使用bash 使用sed 如何取代""


取代文件 內容

testver = "123"


bash 內容

testv1=$(cat "/home/test/test.cfg" | grep 'test' |awk -F 'test' '{printer $2}'

sed -i "s/test=$test1/ver=$test2 /g" /home/test.cfg

但卻無法成功 如果是直接用數字替換是自是可以的

bash 要如何取代""

目的test= "123" 替換成 test= "456"



--

All Comments

Kristin avatarKristin2015-08-28
題意不清,請舉具體一點的實例。
Agnes avatarAgnes2015-09-01
sed -i 's/test="123"/test="345"/' /home/test.cfg
是這個意思嗎?
Madame avatarMadame2015-09-02
第1行是$testv1 第2行是$test1 是不是你打錯字?
Olivia avatarOlivia2015-09-05
Ed大大 這方式指令方式直接下沒問題 但我是把他寫成ba
sh 就無效 其中我先cat 我要取代的 先寫成變數1要取代
的寫成變數2 這樣無法取代 大大可留即時通訊 方式
給我
Connor avatarConnor2015-09-07
Tristan Cohan avatarTristan Cohan2015-09-12
會問具體實例是因為這樣傳有點醜,可以用其他方式寫
Eartha avatarEartha2015-09-14
找我?irc.mibbit.com #dsptcm 我的 id 是 qtnez
Madame avatarMadame2015-09-17
不過掛在那裡,人不一定在電腦前。XD
John avatarJohn2015-09-20
基本上 grep/sed/awk 是 小弟/二哥/大哥,大哥出馬
時,做小弟的就可以閃到一邊去了。