一致するものを見つけたら、次の行をすべて印刷してください。

一致するものを見つけたら、次の行をすべて印刷してください。

次の a1.txt ファイルがあります。

  a.log.54
  a.log.56
  a.log.57
  a.log.58
  a.log.59
  a.log.110
  a.log.113
  a.log.114
  a.log.115
  a.log.116
  a.log.117
  a.log.118
  a.log.119
  a.log.120
  a.log.121
  a.log.122
  a.log.112
  a.log.123
  a.log.124
  a.log.125
  a.log.126
  a.log.128
  a.log.129
  a.log.130
  a.log.131
  a.log.132
  a.log.133
  a.log.134
  a.log.135
  a.log.136
  a.log.127
  a.log.137
  a.log.139
  a.log.140

a2.txt

  a.log.124
  a.log.125

a2.txt の最初の項目を a1.txt と一致させ、一致が見つかった場合は、次の行をすべて印刷する必要があります。

  a.log.124
  a.log.125
  a.log.126
  a.log.128
  a.log.129
  a.log.130
  a.log.131
  a.log.132
  a.log.133
  a.log.134
  a.log.135
  a.log.136
  a.log.127
  a.log.137
  a.log.139
  a.log.140

ベストアンサー1

このawkスクリプトは機能するはずです。たとえば、a2.txt最初の行を変数に設定してtriggerすぐに使用を開始しますnextfilea1.txtレコードが一致する点から印刷します。trigger

awk 'first{trigger=$0; nextfile}; 
    !first && $0 == trigger{start=1}; 
    start' first=1 a2.txt first=0 a1.txt

おすすめ記事