ログファイルから情報を抽出したい。私が使用しているパターンは、node-nameとコマンドのプロンプトです。コマンド出力の情報を抽出して比較したい。次のようにサンプル出力を検討します
NodeName > command1
this is the sample output
NodeName > command2
this is the sample output
次のコードを試しました。
public static void searchcommand( String strLineString)
{
String searchFor = "Nodename> command1";
String endStr = "Nodename";
String op="";
int end=0;
int len = searchFor.length();
int result = 0;
if (len > 0) {
int start = strLineString.indexOf(searchFor);
while(start!=-1){
end = strLineString.indexOf(endStr,start+len);
if(end!=-1){
op=strLineString.substring(start, end);
}else{
op=strLineString.substring(start, strLineString.length());
}
String[] arr = op.split("%%%%%%%");
for (String z : arr) {
System.out.println(z);
}
start = strLineString.indexOf(searchFor,start+len);
}
}
}
問題は、コードが遅すぎてデータを抽出できないことです。他にそうする方法はありますか?
編集1上記のコードで文字列として読み取ったログファイル。