特定の箇所のみ出力するrubyプログラム
一つのファイルに複数の情報を書き込んでいる際に、以下のように取り出したい内容が区切られているとする。
<HOGE> 取り出したい内容 </endHOGE>
この取り出したい内容を拾い出すプログラムを作成した。
ファイル名は入力で与えている。
file=open(ARGV[0]) lines=file.read().split("\n") export=false lines.each do |line| if line =~/<HOGE>/ export=true end if line =~/<endHOGE>/ export=false end if export then puts(line) end end file.close