Compare-Object删除部分属性

时间:2017-04-06 12:23:47

标签: powershell powershell-v3.0 powershell-v4.0 compareobject

我有代码

'react-vendor': [
   'semantic-ui-react',
 ],

  new CommonsChunkPlugin({
    name: "react-vendor",
    filename: "react-vendor.js",
    minChunks: Infinity,
  }),

我得到的东西看起来像这样

Compare-Object $str $str1 | foreach InputObject | ft -auto | out-file "$resault" -width 5000

我想在我的\\Server\path\path\Config.Current.Running.rt-1.ci.cou.txt .txt档案中只有部分内容= rt-1.ci.cou

1 个答案:

答案 0 :(得分:0)

#Set a variable, Path, with the full string you're looking at
[string]$Path = '\\Server\path\path\Config.Current.Running.rt-1.ci.cou.txt' 

#Remove the directory so we're left with just the filename
[string]$Filename = (Split-Path -Path $Path -Leaf)
#$FileName: Config.Current.Running.rt-1.ci.cou.txt

#use regular expressions to capture the text that appears after the 3rd period (`.`) and before the last period.
$Filename -replace '^[^.]*\.[^.]*\.[^.]*\.(.*)\.[^.]*$', '$1'
#Output: rt-1.ci.cou