PowerShell 코딩의 초보자로서 PowerShell 정규식 패턴에서 변수를 확장하는 데 어려움이 있습니다. 내가하고 싶었던 무엇정규식 패턴의 변수 확장이 작동하지 않습니다.
은 두 시간대 로그 파일 각각에 대해
- 스캔, 나는 그것이로 참조하는 날짜를 나타내는 이름의 일부를 얻을 .
날짜가 변수 $filedate
에 저장됩니다. 내가 보이는 라인을 찾을 때마다 다음 각 행 물마루 이동은 로그 파일 같은 : 나는 데이터 라인이 글은 출력을 작성해야
2013-06-20 14:00:15 blablabla
가되도록 할 blabla20130620.log
라는 이름의 파일에서
14:00:15 blablabla
다른 로그 파일을 연결하기 위해 텍스트 파일에 모드를 추가하십시오.
여기까지가 지금입니다 (지금 샌드 박스에서 테스트 중이므로 아무런 코멘트가 없습니다 ...)
$Logpath = "o:\Log"
$prevcheck="2013-06-24 19:27:14"
$currenttd="{0:yyyy-MM-dd HH:mm:ss}" -f (get-date)
$batch = 1000
[regex]$match_regex = '^([01]\d|2[0-3]):([0-5]\d):([0-5]\d)'
If (Test-Path "$Logpath\test.txt"){
Remove-Item "$Logpath\test.txt"
}
$files=Get-ChildItem $LogPath\*.log | Where-Object { $_.LastWriteTime -ge "$prevcheck" - and $_.LastWriteTime -le "$currenttd" -and !$_.PSIsContainer }
foreach ($file in $files)
{
$filedate=$file.Name.Substring(6,4) + "-" + $file.Name.Substring(10,2) + "-" + $file.Name.Substring(12,2)
## This doesn't seem to work fine
## results look like:
## "$filedate" 14:00:15 blablabla
$replace_regex = '"$filedate" $_'
## I tried this too, but without success
## The time seems to dissappear now
## results look like:
## 2013-06-20 blablabla
#$replace_regex = iex('$filedate' + $_)
(Get-Content $file.PSPath -ReadCount $batch) |
foreach-object {if ($_ -match $match_regex) { $_ -replace $match_regex, $replace_regex} else { $_ }}|
out-file -Append "o:\log\test.txt"
와우 ... 고마워. 이제 좀 더 이해하려고 노력할 것입니다. – davidthijs