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 最後の行まで削除します。