2017-07-20 11 views
0

で、私は多くのalreadeをawnseredているこのトピックについての質問が、私の場合で私を助け残念ながらどれもが知っている: 私はこのように見ているのserver.logファイルがあります:分割テキストファイルの行と列

 
################################################## 
ServerLog 07.07.2017 1:00:02,02 
Software Version 2.5 (modified 30.06.2017 15:53) 
################################################## 


Number of clients: 4 


KB-Server is online 
--------------------------------------------------------------------- 
--------------------------------------------------------------------- 
Client 1 

current client: \\192.168.0.22\Dauerversuch01 

Connecting the network share successfull? 
client connected successfully 

No files found 
--------------------------------------------------------------------- 
--------------------------------------------------------------------- 
Client 2 

current client: \\192.168.0.23\Dauerversuch01 

Connecting the network share successfull? 
client connected successfully 


3 
Files found in the directory 

Copy from Client to local HDD: 
"\\192.168.0.23\Dauerversuch01 --> D:\Transfer" 
All files passed the md5 check 

Files won't get analysed by GlyphWorks 

copy files from hdd to server: 
"D:\Transfer --> \\mucs0244\Pool\CoC-AS\MessdatenQuantum\Dauerversuch_01_DUMMY\2017\07" 
All files passed the md5 check 

files were transfered successfully from the client to the server 


--------------------------------------------------------------------- 
--------------------------------------------------------------------- 
Client 3 

current client: \\192.168.0.24\Dauerversuch 

Connecting the network share successfull? 
client connected successfully 


3 
Files found in the directory 

Copy from Client to local HDD: 
"\\192.168.0.24\Dauerversuch --> D:\Transfer" 
All files passed the md5 check 

Files won't get analysed by GlyphWorks 

copy files from hdd to server: 
"D:\Transfer --> \\mucs0244\Pool\CoC-AS\MessdatenQuantum\Dauerversuchspruefstand_02_SL20-4\2017\07" 
All files passed the md5 check 

files were transfered successfully from the client to the server 


--------------------------------------------------------------------- 
--------------------------------------------------------------------- 
Client 4 

current client: \\192.168.0.25\Dauerversuch01 

Connecting the network share successfull? 
client connected successfully 


3 
Files found in the directory 

Copy from Client to local HDD: 
"\\192.168.0.25\Dauerversuch01 --> D:\Transfer" 
All files passed the md5 check 

Files won't get analysed by GlyphWorks 

copy files from hdd to server: 
"D:\Transfer --> \\mucs0244\Pool\CoC-AS\MessdatenQuantum\Dauerversuch_01_DUMMY2\2017\07" 
All files passed the md5 check 

files were transfered successfully from the client to the server 



--------------------------------------------------------------------- 
--------------------------------------------------------------------- 
Batch erfolgreich beendet 

あなたはすでに予想通り、server.logをクライアントログに分割したいと思います。具体的には、入力パラメータとしてクライアント番号を指定してPowerShellスクリプトを実行できるようにするには、スクリプトを出力する必要があります。このように見てclient2.log:

 
--------------------------------------------------------------------- 
Client 2 

current client: \\192.168.0.23\Dauerversuch01 

Connecting the network share successfull? 
client connected successfully 


3 
Files found in the directory 

Copy from Client to local HDD: 
"\\192.168.0.23\Dauerversuch01 --> D:\Transfer" 
All files passed the md5 check 

Files won't get analysed by GlyphWorks 

copy files from hdd to server: 
"D:\Transfer --> \\mucs0244\Pool\CoC-AS\MessdatenQuantum\Dauerversuch_01_DUMMY\2017\07" 
All files passed the md5 check 

files were transfered successfully from the client to the server 


--------------------------------------------------------------------- 

を私は何ができる最善のは、この小さなスクリプト

$file = (GC H:\server.log) 
foreach ($line in $file) { 
    if ($line -match "^Client \w+") { 
    $newfile = "$($line.Split(' ')[1]).txt" 
    } else { 
    $line | Out-File -Append $newfile 
    } 
} 

である。しかし、これは動作しません「----」の行を探し正しく動作しません。 。

+0

これらを作成するために使用するソフトウェアのログを変更する必要がありますか?フリーフォームのテキストファイルを解析するのは本当の苦痛です。 – Vesper

+0

実際には不幸なことではありませんが、ソフトウェアを変更して "--------"という行を1つだけ含めるようにしても構いませんが、どちらの方法でもアイデアはありません。 –

+0

"(?s) (?= Client \ s \ d)。*?(?= ---)」は、クライアントのフルブロックと一致する必要があります。そして、もし私が間違っていないとすれば、マッチは配列(?)$ matchにあり、それをループし、マッチの最初の行に基づいてログを書き出します。 _(おそらくいくつかのより良い方法は正規表現を書く)_ – Jonas

答えて

2

個々のクライアントのログファイルへのサーバーのログからクライアントのセクションを抽出するための使用Select-String

$serverlog = 'H:\server.log' 
$re = '(?ms)----+\r?\n(Client \d+)[\s\S]*?----+' 

Select-String -Path $serverlog -Pattern $re -AllMatches | 
    Select-Object -Expand Matches | 
    ForEach-Object { 
     $clientlog = 'C:\path\to\{0}.log' -f $_.Groups[1].Value 
     $_.Groups[0].Value | Set-Content $clientlog 
    } 
0

は1からクライアント番号を提供し、連続している、
このスクリプトは、現在のフォルダにあるようにログを前提としています。

$Splitter='-'*69 
$ClientLogs =(Get-Content .\server.log -raw) -split "$Splitter`r?`n$Splitter" 
For ($i=1; $i -lt $ClientLogs.Count-1; $i++){ 
    Set-Content -Path (".\Client_$i.log") -Value $ClientLogs[$i] 
} 
関連する問題