如何使用powershell在文本文件中输出特定字符串

如何使用powershell在文本文件中输出特定字符串,powershell,powershell-2.0,powershell-3.0,powershell-ise,Powershell,Powershell 2.0,Powershell 3.0,Powershell Ise,我有a.txt和b.txt。 A.txt包含{2b,3c,5e,8h},B.txt包含{1a,2b,3c,4d,5e,6f} 我想比较这两个文件,并且只输出a.txt的内容,即“8h” 我尝试过比较对象命令。但它给出了区别。请提供帮助鉴于数据的格式与上述格式完全相同,您可以使用: $a = '{2b,3c,5e,8h}' $b = '{1a,2b,3c,4d,5e,6f}' Compare-Object -ReferenceObject $a.Trim('}', '{').Split(','

我有a.txt和b.txt。 A.txt包含{2b,3c,5e,8h},B.txt包含{1a,2b,3c,4d,5e,6f}

我想比较这两个文件,并且只输出a.txt的内容,即“8h”


我尝试过比较对象命令。但它给出了区别。请提供帮助

鉴于数据的格式与上述格式完全相同,您可以使用:

$a = '{2b,3c,5e,8h}'
$b = '{1a,2b,3c,4d,5e,6f}'

Compare-Object -ReferenceObject  $a.Trim('}', '{').Split(',') -DifferenceObject $b.Trim('}', '{').Split(',') | Where-Object {$_.SideIndicator -eq '<='}
$a='{2b,3c,5e,8h}'
$b=“{1a,2b,3c,4d,5e,6f}”

比较Object-ReferenceObject$a.Trim('}','{').Split('}',')-DifferenceObject$b.Trim('}','{').Split(','))|其中Object{$\ SideIndicator-eq'@Han如果它对您有帮助,请将其标记为答案,这样其他人也会受益。