简体   繁体   English

替换导入的 CSV 文件中的字符串/多个条件

[英]Replace string in an imported CSV file / multiple conditions

I need to import a CSV file and then replace the string domain\username AND the string domain\login with the word SSO .我需要导入一个 CSV 文件,然后将字符串domain\username和字符串domain\login替换为单词SSO

I know that replacing only domain\username would be:我知道仅替换domain\username名将是:

(Get-Content $ImportCPUFile) |
    ForEach-Object { $_ -replace '"domain\username"', '"sso"' } |
    Out-File -FilePath CSV-cleaned.csv -Force -Encoding ascii

But how to make an OR statement in the ForEach-Object function for domain\username and domain\login ?但是如何在ForEach-Object function 中为domain\usernamedomain\login做一个 OR 语句呢? I tried:我试过了:

(Get-Content $ImportCPUFile) |
    ForEach-Object {$_ -replace '"domain\username"', '"sso"' -or $_ -replace '"domain\login"', '"sso"'} |
    Out-File -FilePath CSV-cleaned.csv -Force -Encoding ascii

But it returns only TRUE statements.但它只返回 TRUE 语句。

Try RegEx or '|'尝试正则表达式或“|”

(Get-Content $ImportCPUFile) |
ForEach-Object { $_ -replace '"domain\\username"|"domain\\login"', '"sso"' } |
Out-File -FilePath CSV-cleaned.csv -Force -Encoding ascii

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM