SED または AWK は、最初のダッシュの前と最後のダッシュの後のすべての項目を削除します。

SED または AWK は、最初のダッシュの前と最後のダッシュの後のすべての項目を削除します。

私はいくつかの追加内容を含む秘密鍵ファイルを持っており、鍵のテキストだけが欲しいです。

だから:

nonsense -----Begin Key-----
keep this1
keep this2 
keep this3
-----End Key----- nonsense

しなければならない

-----Begin Key-----
keep this1
keep this2 
keep this3
-----End Key-----

編集:実際の単語「ゴミ」を削除したくありません。コアテキストの前後に何でも構いません。

ベストアンサー1

どうですか?

sed -e '/Begin Key/ s/^[^-]*//' -e '/End Key/ s/[^-]*$//'

前任者。

$ sed -e '/Begin Key/ s/^[^-]*//' -e '/End Key/ s/[^-]*$//' file
-----Begin Key-----
keep this1
keep this2 
keep this3
-----End Key-----

おすすめ記事