나는 응용 프로그램 서버에서 alog를 가지고 있는데, 나는 "E"플래그 또는 "W"가있는 라인을 가져야한다.perl에서 특정 행을 구문 분석하는 방법은 무엇입니까?
나는 스크립트를 알아 내려고 시도 : 사전에
#!/usr/bin/perl
use strict;
use warnings;
my $msg;
my $line;
my $line2;
main(@ARGV);
sub rec {
#$msg= $line;
print $line;
while ($line2 = <FH>) {
if ($line2 !~ m/^\[/){
#$msg = $msg.$line2;
print $line2;
} else {
if($line2 =~ m/ E | W /) { rec(); }
last;
}
}
#print $msg;
}
sub main {
open(FH,'SystemOut_15.02.05_17.00.02.log') or die "Error openong file : $!";
while ($line = <FH>) {
if($line =~ m/ E | W/and $line =~ m/^\[/){
rec();
}
}
close FH;
}
감사합니다. 로그의
샘플 : 내가 얻을 필요가있는 무엇
[2/5/15 14:55:18:025 UTC] 0000003a JDBCException W org.hibernate.util.JDBCExceptionReporter logExceptions SQL Error: 17006, S
QLState: null
*********************************************************** Start Server *******************************
0000003a JDBCException O OK
0000003a JDBCException O OK
********************************************************** End Server *******************************
[2/5/15 14:55:18:025 UTC] 0000003a JDBCException W org.hibernate.util.JDBCExceptionReporter logExceptions SQL Error: 17006, S
QLState: null
org.hibernate.util.JDBCExceptionReporter
org.hibernate.util.JDBCExceptionReporter
org.hibernate.util.JDBCExceptionReporter
[2/5/15 14:55:18:025 UTC] 0000003a JDBCException E org.hibernate.util.JDBCExceptionReporter logExceptions SQL Error: 17006, S
QLState: null
org.hibernate.util.JDBCExceptionReporter
org.hibernate.util.JDBCExceptionReporter
org.hibernate.util.JDBCExceptionReporter
[2/5/15 14:55:18:025 UTC] 0000003a JDBCException O OK
[2/5/15 14:55:18:025 UTC] 0000003a JDBCException O OK
[2/5/15 14:55:18:025 UTC] 0000003a JDBCException O OK
[2/5/15 14:55:18:025 UTC] 0000003a JDBCException O OK
[2/5/15 14:55:18:025 UTC] 0000003a JDBCException W org.hibernate.util.JDBCExceptionReporter logExceptions SQL Error: 17006, S
QLState: null
[2/5/15 14:55:18:025 UTC] 0000003a JDBCException O OK
[2/5/15 14:55:18:025 UTC] 0000003a JDBCException O OK
[2/5/15 14:55:18:025 UTC] 0000003a JDBCException O OK
[2/5/15 14:55:18:025 UTC] 0000003a JDBCException O OK
[2/5/15 14:55:18:025 UTC] 0000003a JDBCException E org.hibernate.util.JDBCExceptionReporter logExceptions SQL Error: 17006, S
QLState: null
org.hibernate.util.JDBCExceptionReporter
org.hibernate.util.JDBCExceptionReporter
org.hibernate.util.JDBCExceptionReporter
[2/5/15 14:55:18:025 UTC] 0000003a JDBCException O OK
[2/5/15 14:55:18:025 UTC] 0000003a JDBCException O OK
[2/5/15 14:55:18:025 UTC] 0000003a JDBCException O OK
[2/5/15 14:55:18:025 UTC] 0000003a JDBCException O OK
:
[2/5/15 14:55:18:025 UTC] 0000003a JDBCException W org.hibernate.util.JDBCExceptionReporter logExceptions SQL Error: 17006, S
QLState: null
[2/5/15 14:55:18:025 UTC] 0000003a JDBCException W org.hibernate.util.JDBCExceptionReporter logExceptions SQL Error: 17006, SQLState: null
org.hibernate.util.JDBCExceptionReporter
org.hibernate.util.JDBCExceptionReporter
org.hibernate.util.JDBCExceptionReporter
[2/5/15 14:55:18:025 UTC] 0000003a JDBCException E org.hibernate.util.JDBCExceptionReporter logExceptions SQL Error: 17006, SQLState: null
org.hibernate.util.JDBCExceptionReporter
org.hibernate.util.JDBCExceptionReporter
org.hibernate.util.JDBCExceptionReporter
[2/5/15 14:55:18:025 UTC] 0000003a JDBCException W org.hibernate.util.JDBCExceptionReporter logExceptions SQL Error: 17006, SQLState: null
[2/5/15 14:55:18:025 UTC] 0000003a JDBCException E org.hibernate.util.JDBCExceptionReporter logExceptions SQL Error: 17006, SQLState: null
org.hibernate.util.JDBCExceptionReporter
org.hibernate.util.JDBCExceptionReporter
org.hibernate.util.JDBCExceptionReporter
시작과 정지 사이의 라인을 무시하는 한 강력한 방법은 ysth로 나타낸 바와 같이, 플립 플롭을 사용하는 것입니다; 기타 (약한) 방법 :
open(my $fh, '<', 'test2.log') or die "Error opening file : $!";
my $match = 0;
while (my $line = <$fh>) {
if ($line =~ /^\*+/){
$match = 0; ## initialize match if line start with star
}
if ($line =~ /^\[/) {
$match = $line =~ m/ E | W /;
}
print $line if $match;
}
close $fh;
단 한 줄의 의미 라인 (당신이 그것을 발견 할 때 찾고 중지)? 당신의 코드가 무엇을 의미하는지 설명 할 수 있습니까? 그것은 당신이 당신이 추출 기대하는지 입력 샘플을 제공 할 수 있습니다 – ysth
을 원하는 당신의 설명보다 더 복잡 많이 보인다? – Sobrique
@ ysth/@Sobrique : 아니, 그것은 각 경기 후 패턴 –