現在、入力ファイル (.log) から次の形式の一連の ping レポートを取得するログ パーサーを作成しようとしています: (194.12.224.34 からの 64 バイト: icmp_seq=1 ttl=47 time=66.7 ms) および出力ファイル (.csv) を作成します。
何度も試行した後、以下のエラーが発生しました。私の同僚は私に彼のコード (以下) をくれました。これは別の方法で書かれていますが、本質的には同じです。彼のコードは同じエラーを出しますが、当然のことながら、彼のコードは同じタスクで問題なく動作します。どんな援助でも大歓迎です!
私は今、最初の 2 つの正規表現の動作は問題ないと考えています。3 つ目は問題です。以下は、私が解析しようとしているものです:
120 パケット送信、120 受信、0% パケット損失、時間 119247ms rtt min/avg/max/mdev = 65.944/67.381/72.714/1.728 ms
初投稿です、至らぬ点がありましたら申し訳ありません。
$INPUT = "ping.log";
$OUTPUT = "pingParsed.csv";
# > operator puts the write function in overwrite mode rather than append.
open (INPUT, '<', $INPUT);
open (OUTPUT, '>', $OUTPUT);
while (<INPUT>) {
# if (timestamp regex)
if(/(\w{3})\s+(\w{3})\s+(\d+)\s+(\d+):(\d+):(\d+)\s+GMT\s+(\2013)/) {
# print OUTPUT (date regex variables, $1 = Day, $2 = Month, $3 = Day, $4 = hour, $7 = year)
print OUTPUT "$1 , $2 , $3 , $4 , $7";
$headers = "IP, Seq, Time";
print OUTPUT "$headers";
}
# if (ping info regex, $1 = IP address, $2 = Seq, $3 = Time)
if ( m/icmp_seq=
(\S+)
\s+ttl=
(\S+)
\s+time=
(\S+) /x) # x allows use of whitespaces and comments in the regex.
{
print "$1, $2, $3\n";
}
# if (regex for total ping info - I think this is line 55.)
if (/\d+\d+\d+\s+\packets\s+\transmitted,\s+\d+\d+\d+\s+\received,\s+(\d+)\s+\packet\s+\loss,\s+time\s+(\d+)\ms\s+\min\avg\max\mdev\s+=\s+(\(S+)\\/\(S+)\\/(S+)\\/\(\S+)\s+\ms/) {
headers:
print ("$15 = packet loss(%), $22 = time(ms), $28 = rttmin, $33 = arg, $35 = max, $37 = ndev");
print OUTPUT ($15, $22, $28, $33, $35, $37);
}
}
close $INPUT;
close $OUTPUT;
エラー:
Backslash found where operator expected at ./pingParseScript.pl line 55, near "/\d+\d+\d+\s+\packets\s+\transmitted
(Missing operator before \?)
./pingParseScript.pl 行 55 の ")\" 付近で演算子が予期される場所にバックスラッシュが見つかりました (\? の前に演算子がありません) ?) ./pingParseScript.pl 行 55 の構文エラー、"/\d+\d+\d+\s+\packets\s+\transmitted,\s+\d+\d+\d+\s+\received,\ で終了しない置換パターン./pingParseScript.pl 55 行目。