ログファイルから特定の行を抽出する

ログファイルから特定の行を抽出する

以下のログファイルがあります。

 - UTT (1): test_1978_recreatie_1656.wav
lattice-to-ctm-conf ark:- output/spk001_test_1978_recreatie_1656_1bestsym.ctm 
online2-wav-nnet3-latgen-faster --online=false --do-endpointing=false --frame-subsampling-factor=3 --config=exp/tdnn1a_sp_bi_online/conf/online.conf --max-active=7000 --beam=15.0 --lattice-beam=6.0 --acoustic-scale=1.0 --word-symbol-table=exp/tdnn1a_sp_bi_online/graph_s/words.txt exp/tdnn1a_sp_bi_online/final.mdl exp/tdnn1a_sp_bi_online/graph_s/HCLG.fst 'ark:echo spk001 test_1978_recreatie_1656|' 'scp:echo test_1978_recreatie_1656 raw_data/spk001/test_1978_recreatie_1656.wav|' ark:- 
test_1978_recreatie_1656 wij zullen <unk> 
LOG (online2-wav-nnet3-latgen-faster[5.5.929~1-9bca2]:main():online2-wav-nnet3-latgen-faster.cc:296) Decoded utterance test_1978_recreatie_1656
LOG (lattice-to-ctm-conf[5.5.929~1-9bca2]:main():lattice-to-ctm-conf.cc:175) For utterance test_1978_recreatie_1656, Bayes Risk 4.06451, avg. confidence per-word 0.636305
 - UTT (1): test_1978_recreatie_1656.wav, time: 1 seconds
 - UTT (2): test_1978_recreatie_1657.wav
lattice-to-ctm-conf ark:- output/spk001_test_1978_recreatie_1657_1bestsym.ctm 
online2-wav-nnet3-latgen-faster --online=false --do-endpointing=false --frame-subsampling-factor=3 --config=exp/tdnn1a_sp_bi_online/conf/online.conf --max-active=7000 --beam=15.0 --lattice-beam=6.0 --acoustic-scale=1.0 --word-symbol-table=exp/tdnn1a_sp_bi_online/graph_s/words.txt exp/tdnn1a_sp_bi_online/final.mdl exp/tdnn1a_sp_bi_online/graph_s/HCLG.fst 'ark:echo spk001 test_1978_recreatie_1657|' 'scp:echo test_1978_recreatie_1657 raw_data/spk001/test_1978_recreatie_1657.wav|' ark:- 
test_1978_recreatie_1657 we kunnen dat wel zeggen 
LOG (online2-wav-nnet3-latgen-faster[5.5.929~1-9bca2]:main():online2-wav-nnet3-latgen-faster.cc:296) Decoded utterance test_1978_recreatie_1657
LOG (lattice-to-ctm-conf[5.5.929~1-9bca2]:main():lattice-to-ctm-conf.cc:175) For utterance test_1978_recreatie_1657, Bayes Risk 0.654865, avg. confidence per-word 0.922916
 - UTT (2): test_1978_recreatie_1657.wav, time: 0 seconds

ログファイルにはUTT(n)の4行目の記録があり、Linuxコマンドを使用してそれらを抽出したいと思います。たとえばtest_1978_recreatie_1657 we kunnen dat wel zeggentest_1978_recreatie_1656 wij zullen <unk> 以前は特定のパターン抽出のためにgrepコマンドを探していましたが、成功しませんでした。どうすればいいのかご提案ください。

ベストアンサー1

あなたが要求するのは、発生後に4行目を印刷し、UTT (n)毎回カウンタを1にリセットすることですUTT (n)

awk '/UTT \([0-9]+\)/{line=0} {line++} line==4' file

出力

test_1978_recreatie_1656 wij zullen <unk>
test_1978_recreatie_1657 we kunnen dat wel zeggen

いくつかの説明。どちらかがオプションのawkフォーム行です(両方ではありません)。各入力行は、すべてのモード/作業コマンドに順次適用されます。欠落モードとは、各入力ラインに対して操作が実行されることを意味します。欠落は、入力行が印刷されることを意味します。pattern {action}patternactionaction

/UTT \([0-9]+\)/ {line=0}    # Match the pattern to set line=0
{line++}                     # Each line of input increments line
line==4                      # When line==4, implicitly print the line

おすすめ記事