0
我的PowerShell CSV工具有一個奇怪的問題。我試圖寫一個小的檢查過濾掉某些名字和字符。這些名稱/字符是在這樣一個文本文件:-notmatch ...(3個點)
XXX nana YYY ... DDD
我做檢查的謊言是:
$reader = [System.IO.File]::OpenText($fc_file.Text)
try {
for() {
$line = $reader.ReadLine()
if ($line -eq $null) { break }
# process the line
Import-Csv $tempfile -Delimiter $delimeter -Encoding $char |
where {$_.$fc_suchfeld -notmatch $line} |
Export-Csv $tempstorage -Delimiter $delimeter -Encoding $char -NoTypeInfo
它的偉大工程,直到三個點就行了。此時幾乎所有行都被刪除。我怎麼解決這個問題?
'.'是任何一個字符匹配通配符,所以'某事'不匹配'...''幾乎總是錯誤的。如果你只是想從字面上匹配事物,可以考慮使用'-notlike'(但不要使用'*'和'?',它們是''''''的通配符)。如果你想成爲真正的文字,使用'-not $ _。$ fc_suchfeld.Contains($ line)'(假設'$ _。$ f_suchfeld'是一個字符串)。 –