設定ファイルがあるとしましょう。
[main]
foo = bar
[option]
opt1 = opt2
opt3 = opt4
[extra]
[footer]
[tail]
print = true
[end]
[text]
以下のオプションがある場合にのみタイトル()を印刷したいと思います。したがって、出力は次のようになります。
[main]
foo = bar
[option]
opt1 = opt2
opt3 = opt4
[tail]
print = true
ベストアンサー1
通常、読みやすくするために複数行で書いていますが、1行を要求したので、
perl -ne '$head = $_ and next if /^\[/; $head and print $head and undef $head; print'