[英]Get-Content and Set-Content with specific lines and seperated
我正在使用以下代碼在很大的csv文件中查找包含字符串的行,然后將字符串所在的行打印到.log文件中。
我正在使用以下代碼...
$fileContents = Get-Content $testReport -TotalCount 1
$fileContents += Get-Content $testReport -ReadCount 1000 | ForEach {$_ -match $myString}
$fileContents | Set-Content 'C:\Temp\test1.log'
而不是獲得以下內容:
firstLine
line
line
line
我得到這個:
firstLine
linelineline
任何幫助都會很棒。
似乎這是最好的方法...
Import-Csv $testReport |
Where-Object {$_.columnName -eq $myString} |
Export-Csv 'C:\Temp\test1.log' -NoTypeInformation -Force
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.