履歴を含むファイルがあります。記録形式は次のとおりです。
Record: XXXXXX [
{variable number of lines and content}
]
記録のある時点で、以下があるかもしれません。
Start to do this thing
「start」という単語に一致するレコード番号とレコードの行を抽出したいと思います。
現在私が使用している
egrep "Record|Start" inputfile.txt >> outputfile.txt
Record
ただし、一致しない一致する行を手動で削除する必要がありますStart
。理想的には、このステップが完了することを願っています。どんな提案にも感謝します。
ベストアンサー1
アッ解決策:
サンプルinput.txt
ファイル:
Record: 111111 [
text
test
Start to do this thing
text
]
Record: 222222 [
{variable number of lines and content}
]
Record: 333333 [
text
text
text
Start to do another thing
text
]
働く:
awk '/^Record: .*\[$/{ f=1; n=$2 }/^\]/{f=0}f && /^Start/{ print n, $0 }' input.txt
出力:
111111 Start to do this thing
333333 Start to do another thing