2015-12-18 29 views
1

我使用下面的代碼來查找包含非常大的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 

有任何幫助這將是偉大的。

回答

0

看起來這是最好的辦法......

Import-Csv $testReport | 
    Where-Object {$_.columnName -eq $myString} | 
     Export-Csv 'C:\Temp\test1.log' -NoTypeInformation -Force