揮発性のメモ2

http://d.hatena.ne.jp/iww/

STARTとENDに挟まれた行を別のファイルと置換する

a.txt

the world
stop time
START
this
is my world
END
and time resumes

a.txt のうち、START と END に挟まれた部分を別ファイルb.txtと置換する
ただしSTARTとENDの行は残す


sedの場合

sed -n '1,/START/p' a.txt; cat b.txt; sed -n '/END/,$p' a.txt

perlの場合

perl -ne 'if(!$a){print; $a=$_=~/START/ and print`cat b.txt`}elsif(!$b){$b=$_=~/END/ and print}else{print}' a.txt

とりあえず出来た。 これを短くする。