他のパターンの後に表示されるパターンで始まる行全体を削除します。

他のパターンの後に表示されるパターンで始まる行全体を削除します。

次を含む行(行番号の最初の項目)---の後の行番号に表示される行を削除するには?# Match


編集する:

#Matchで始まる行との関係は、---後者が前または後に存在する可能性がありますが、#Match後に存在する場合にのみ削除する必要があることです#Match。 –

入力サンプル

hello

this is sample
--- sdafasdf
adsafasf
asfas
fasf

#Match
this is sample
adsafasf
asfas    dafasf
------ lots of fun
---- test

adsfasf****

期待される出力

hello

this is sample
--- sdafasdf
adsafasf
asfas
fasf

#Match
this is sample
adsafasf
asfas    dafasf

adsfasf****

ベストアンサー1

あなたの質問に応じて、このtext.txtを作成しました。ファイルの内容が異なる場合はお知らせください。

bash-4.1$ cat test.txt
#Match
---- test
hello
#Match
this is sample
adsafasf
asfas
fasf
#Match
------ funny
------ lots of fun
#Match
dafasf
adsfasf

bash-4.1$ awk '/#Match/ {flag=1} flag && /^---/ {flag=0;next} 1' test.txt
#Match
hello
#Match
this is sample
adsafasf
asfas
fasf
#Match
------ lots of fun
#Match
dafasf
adsfasf

おすすめ記事