之前添加多個保存在變量中的內襯字符串我一直在嘗試很多方法,但沒有運氣。我有一個名爲test.txt的文件,它有一些lorem ipsum和文本[staging:production]我只想添加幾行,我保存在一個變量之前。查找一個字符串並在
如果你能解釋我在哪裏出錯了,下面的任何內容都將非常感謝!
#!/bin/bash
test="lala\
kjdsh"
sed '/^#$/{N; /[staging: production]/ i \
<Location /cgis> \
</Location>\
}' ./test.txt
sed -i -e 's/\[staging\: production\]/\$test/g' ./test.txt
#sed -i 's/Lorem/beautiful/g' test.txt
#awk -v data=$test '{A[NR]=$0}/\[staging\: production\]/{ print data }' test.txt > testfile.txt
#read -a text <<<$(cat test.txt)
#echo ${#text[@]}
#for i in ${text[@]};
#do
# echo -n $i;
# sleep .2;
#done
#ed -s test.txt <<< $'/\[staging\: production\]/s/lalalala/g\nw'
#awk -v data=$test '/\(/\[staging\: production\]\)/ { print data }' test.txt > testfile.txt
# && mv testfile.txt test.txt
#sed -i -e '/\(\[staging\: production\]\)/r/$test\1/g' test.txt
#sed "/\(\[staging\: production\]\)/s//$test\1/g" test.txt
當您使用反斜槓作爲續行字符時,行連接就像沒有換行符一樣。刪除反斜線並保留換行符。 – 2012-08-13 23:37:22