範例A
來源:
2016-03-08 17:03:29 Local7.Debug 1.2.3.4 20 (886,3) FXS
601 1 17:02:49 OUT 00:00:11 0007B 0 11
2016-03-08 17:04:42 Local7.Debug 10.1.3.47 31 (886,7) FXS
601 1 17:03:35 OUT 00:01:08 0007C 0 11
程式碼:
Set-Location -Path D:\temp\data
$context = Get-ChildItem
echo $context.name
foreach($FileName in $context.name){
$file= Get-Content D:\temp\data\$FileName
foreach($item in $file)
{
if( $item -match("^((19|20)?[0-9]{2}[- /.](0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01]))"))
{
$data=$item
}else{
$data=$Data+";"+$item
Write-Host $data
add-content -path D:\temp\Temp1.txt -value $data
}
}
}
輸出結果:
2016-03-08 17:03:29 Local7.Debug 1.2.3.4 20 (886,3) FXS;601 1 17:02:49 OUT 00:00:11 0007B 0 11
2016-03-08 17:04:42 Local7.Debug 4.3.2.1 31 (886,7) FXS;601 1 17:03:35 OUT 00:01:08 0007C 0 11
請問如何參照以上範例修改下列需求呢??
來源:(一筆資料為四行)
UDP:
192.168.5.122 2000 88632123456
63^61152 1 08:43:35 00:00:52 A 8861234567891 2016/09/01
#UDP:
192.168.5.123 2000 88632123456
61^61152 1 08:43:35 00:00:52 A 8861234567892 2016/09/01
程式碼:
???
目標顯示:
UDP: 192.168.5.122 2000 88632123456 63^61152 1 08:43:35 00:00:52 A 8861234567891 2016/09/01