sed
「start」の入力ファイルを検索し、「next」を含む行を見つけて、次の行を表示するスクリプトを作成するにはどうすればよいですか?このような:
[user]$ cat test.txt
start
next
This line should print
Ignore this
[user]$ display.sed test.txt
This line should print
[user]$ cat test1.txt
Ignore this
next
Ignore this
start
Ignore this
next
This line should print
Ignore this
next
Too late so ignore this too
start
Ignore this too
[user]$ display.sed test1.txt
This line should print
ベストアンサー1
範囲(最初からstart
ファイルの終わりまで)を使用して、d
その範囲内で一致しないすべての行を削除できますnext
。行が一致する場合は、n
次の行を読んでp
印刷してから、q
次のように入力します。
sed -n '/start/,${
/next/!d;n;p;q
}' infile
あなたが本当に欲しいのは、次のものを含むファイルだと思いますdisplay.sed
。
#!/bin/sed -nf
/start/,${
/next/!d;n;p;q
}