Cari string antara dua cap waktu mulai dari bawah file

0

Saya sedang berusaha menemukan string Cannot proceed: the cube has no data dalam file test.txt besar hanya antara cap waktu kemarin 22:30 hingga hari ini 00:30 pagi.

Naskah:

tac test.txt | awk -v today=$(date "+%d") -v yesterday=$(date "+%d" -d yesterday) '/Cannot proceed: the cube has no data/ {f=$0; next} f{if (($3==yesterday && $4>"22:30:00") || ($4==today && $4<="00:30:00")) {print; print f} f=""}'

test.txt:

[Thu Jun  8 07:56:17 2014]Local/data///47480280486528/Info(1019022)
Writing Database Mapping For [data]

[Thu Jun  8 12:56:38 2014]Local/data///47480280486528/Info(1250008)
Setting Outline Paging Cachesize To [8192KB]

[Thu Jun  8 22:56:20 2014]Local/data///47480280486528/Info(1013202)
Cannot proceed: the cube has no data 

[Thu Jun  8 23:26:18 2014]Local/data///47480280486528/Info(1013205)
Received Command [Load Database]

[Thu Jun  9 00:16:23 2014]Local/data///47480280486528/Info(1019018)
Writing Parameters For Database 

[Thu Jun  9 00:21:20 2014]Local/data///47480280486528/Info(1013205)
Writing Parameters For Database 

[Thu Jun  9 00:29:00 2014]Local/data///47480280486528/Info(1013205)
Cannot proceed: the cube has no data

[Thu Jun  9 01:25:21 2014]Local/data///47480280486528/Info(1019018)
Cannot proceed: the cube has no data 

keluaran:

[Thu Jun  8 22:56:20 2014]Local/data///47480280486528/Info(1013202)
Cannot proceed: the cube has no data

Mengapa tidak semua string yang cocok dengan persyaratan datang dalam output? apa yang saya lewatkan di sini?

Sunny
sumber

Jawaban:

1
awk -v RS="" \
    -v yesterday="$(date "+%e" -d yesterday)" \
    -v start_time="22:30:00" \
    -v today="$(date "+%e")" \
    -v end_time="00:30:00" '
        $3 == yesterday && $4 > start_time {p=1}
        p && $3 == today && $4 > end_time {exit}
        p && /Cannot proceed: the cube has no data/
' test.txt 
[Thu Jun  8 22:56:20 2014]Local/data///47480280486528/Info(1013202)
Cannot proceed: the cube has no data 
[Thu Jun  9 00:29:00 2014]Local/data///47480280486528/Info(1013205)
Cannot proceed: the cube has no data
glenn jackman
sumber
Bug Anda: $4==today harus menggunakan $3
glenn jackman