열이 Powershell의 CSV와 부분적으로 또는 완벽하게 일치하는 경우 행을 반환합니다.

열이 Powershell의 CSV와 부분적으로 또는 완벽하게 일치하는 경우 행을 반환합니다.

기본적으로 문자열을 검색하고 전체 또는 부분 일치 항목을 CSV 형식으로 반환하고 싶습니다.

$Shoes다음과 같은 객체가 있다고 가정해 보겠습니다 .

"Brand","Style","Color","Price"
"Reebok","Basketball","Red/Black","$50"
"Vans","Slip-On","White/Black","$60"
"Vans","Old Skool","Red/White","$60"
"Nike","Sneakers","Red","$50"
"Adidas","Sneakers","Blue","$55"

더 읽기 쉽게 만들기 위해 테이블 ​​형식은 다음과 같습니다.

Brand       Style       Color       Price
-----       -----       -----       -----
Reebok      Basketball  Red/Black   $50
Vans        Slip-On     White/Black $60
Vans        Old Skool   Red/White   $60
Nike        Sneakers    Red         $50
Adidas      Sneakers    Blue        $55

입력 $Shoes -like '*Red*'결과:

@{Brand=Reebok; Style=Basketball; Color=Red/Black; Price=$50}
@{Brand=Vans; Style=Old Skool; Color=Red/White; Price=$60}
@{Brand=Nike; Style=Sneakers; Color=Red; Price=$50}

그러나 내가 찾고 있는 결과는 다음과 같습니다.

Brand       Style       Color       Price
-----       -----       -----       -----
Reebok      Basketball  Red/Black   $50
Vans        Old Skool   Red/White   $60
Nike        Sneakers    Red         $50

내가 여기서 뭘 잘못하고 있는 걸까?

답변1

시도했을 때 -match 형식을 잘못 지정한 것 같습니다. 간단한 해결 방법이 밝혀졌습니다...

그것은 단순히$Shoes -match 'Red'

관련 정보