2017-12-07 21 views
0
 
SubClient   Status 
POD5_vcprd01 
POD4_vcprd01 
POD15_VCPRD01_New 
POD11_2_vcprd01 
POD11_1_vcprd01 
POD12_vcprd01 
POD13_vcprd01_new 
POD10_vcprd01_NEW 

에서 문자를 제거 나는 CSV에 위의 표에서 _new & _New을 제거하기 위해 노력하고 있습니다. 아래 스크립트를 작성했습니다 :문자열

$report = @() 
$Pod_SC = Import-csv "above table" 

foreach($Podclient in $pod_sc) 
{ 
$Client = $Podclient.Subclient 
$Subclient = $Client.Substring(0,$Client.IndexOf('_N')) 
$Status = $Podclient.Status 

$object = New-Object -TypeName PSobject 

$object | Add-Member -MemberType NoteProperty -Name "Subclient" -Value $SubClient 

$object | Add-Member -MemberType NoteProperty -Name "Status" -Value $Status 

$report += $object 
} 

하지만 작동하지 않습니다. 예상 출력은 대소 문자를 구분 당신이 함께 _New_new 모두 처리 할 수있다 ireplace를 사용하는 경우

 
SubClient   Status 
POD5_vcprd01 
POD4_vcprd01 
POD15_VCPRD01 
POD11_2_vcprd01 
POD11_1_vcprd01 
POD12_vcprd01 
POD13_vcprd01 
POD10_vcprd01 
+1

왜 당신은 그냥 ""로 대체하지 않습니다 -ireplace "_new","_old" 내 예와 같이 동일? – SPlatten

+0

'(Get-Content $ file) -replace '_new'| 세트 내용 $ 파일' –

+0

감사합니다. 덕분에 –

답변

0

그냥 대체 텍스트로 취급합니다.

(Get-Content file.csv) -ireplace "_new","" | Set-Content file.csv 

당신은 실제로 단지 -ireplace "_new"를 사용할 수 있지만 교체보다는 구문을 제거하고 싶다면

+0

감사합니다. 그것이 작동합니다 –

+0

당신이 내 대답에 만족한다면 기꺼이 도울 수 있어요 [받아 들일 수있는 것으로 표시 할 수 있습니다] (http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work)). –

+1

PowerShell은 기본적으로 대소 문자를 구분하지 않으므로'-ireplace'와'-replace'는 동일합니다. –