之前添加多个保存在变量中的内衬字符串我一直在尝试很多方法,但没有运气。我有一个名为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