GNU/Linux >> Linux の 問題 >  >> Linux

2つのパターン間の(および除外する)行を印刷しますか?

cURLを使用してフォームを送信します。この場合、コンテンツの一部は、sedを使用して選択された他のファイルから取得されます。

param1の場合 sedを使用した他のファイルからのラインマッチングパターンです 、以下のコマンドは正常に機能します:

curl -d param1="$(sed -n '/matchpattern/p' file.txt)" -d param2=value2 http://example.com/submit

さて、問題に行きましょう。一致するパターン自体を除いて、2つの一致するパターンの間のテキストのみを表示したい。

file.txtとしましょう 含まれるもの:

Bla bla bla
firstmatch
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.
secondmatch
The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English.

現在、多くの「2つの一致するパターンの間」のsed コマンドはfirstmatchを削除しません およびsecondmatch

結果を次のようにしたいと思います:

It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.

承認された回答:

これがあなたがそれをすることができる1つの方法です:

sed '1,/firstmatch/d;/secondmatch/,$d' 

説明:最初の行から firstmatchに一致する行まで 、 消去。一致する行からsecondmatch 最後の行まで削除します。


Linux
  1. ncおよびpvコマンドを使用して2台のコンピューター間でファイルを転送する方法

  2. Crocを使用してコンピュータ間でファイルとフォルダを安全に転送する

  3. それらを含む2つのパターン間の最初の発生を選択する方法は?

  1. SCPとFTPを使用してLinuxのサーバー間でファイルを転送する方法

  2. 2つのパターンの間(およびそれを含む)の線を印刷しますか?

  3. 一致する行と一致する行からN番目の行を印刷しますか?

  1. 各50行から15行目と25行目を印刷する方法は?

  2. 2つのファイル間の共通行?

  3. 2つの特定の行の間にテキストを抽出しますか?