1

sed正規表現に一致するもの (包括的) から他の正規表現に一致するもの (包括的) に印刷行を作成する方法ですが、条件が追加されています - 終了正規表現がまったく存在しない可能性があります。

例 1 (区切り正規表現として^START.*andを想定):^END.*

cruft1
cruft2
START print this
print this
print this
END print this too
cruft

例 2:

cruft1
cruft2
START print this
print this
print this
- file ends here

サブ質問: そのような最初の出現のみを出力します。

4

1 に答える 1

1

^START から ^END までのすべての行に一致

 sed -n '/^START/,/^END/p' <file>

最初の出現を印刷

 sed -n '/^START/,/^END/ {p;q;}' <file>
于 2013-03-03T11:12:09.673 に答える