powershell - 获取内容中的Powershell多重匹配
问题描述
我想看看是否有任何行包含单词“Newer”和/或“New File”。我试过像下面这样的脚本,但没有运气。任何见解将不胜感激。
RoboCopy.exe "C:\Folder" "C:\Folder2" *.* /S /E /MIR /MT:8 /X /V /TS /FP /BYTES /ETA /LOG:C:\Output\log\sync.txt
$SourceDir = "C:\Output\log\"
#$GCI_Fiter = '*.txt'
$Include=@("*.txt")
$FileList = Get-ChildItem -LiteralPath $SourceDir -Include "$Include" -File
foreach ($FL_Item in $FileList) {
$results = Get-Content -Path $FL_Item.FullName | Select-String -pattern '(newer.New File)'
}
Robocopy 日志:
-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows
-------------------------------------------------------------------------------
Started : Wednesday, December 25, 2019 8:16:28 PM
Source : C:\Folder\
Dest : C:\Folder2\
Files : *.*
Options : *.* /V /X /TS /FP /BYTES /S /E /DCOPY:DA /COPY:DAT /PURGE /MIR /ETA /MT:8 /R:1000000 /W:30
------------------------------------------------------------------------------
New File 1 2019/12/25 17:16:04 C:\Folder\2.txt
same 0 2019/12/25 11:38:23 C:\Folder\2\1.txt
same 24 2019/09/25 08:42:17 C:\Folder\5.csv
Newer 1 2019/12/25 17:16:04 C:\Folder\4.txt
100%
same 0 2019/12/11 08:06:39 C:\Folder\1.txt
same 0 2019/12/11 08:06:39 C:\Folder\2.txt
------------------------------------------------------------------------------
解决方案
如果将该文件加载到$InStuff
withGet-Content
中,则可以使用-match
适用于集合的方式。这将为您提供与正则表达式模式匹配的行。像这样 ...
$InStuff -match 'newer|new file'
输出 ...
New File 1 2019/12/25 17:16:04 C:\Folder\2.txt
Newer 1 2019/12/25 17:16:04 C:\Folder\4.txt
推荐阅读
- powershell - PowerShell 核心排序不正确
- laravel - 创建一个给定次数的集合,保持键
- javascript - 下一篇 JS 如何将数据传递给 getStaticProps
- python - 如何在 PyQt5 ScatterPlot 中使用信号
- python-3.x - 如果不是每一行和每一列都有方括号,如何从整个数据框中删除方括号?
- elasticsearch - 如何使图表 c 两种类型:正常和堆叠?
- python - 气流网页启动
- python - 在熊猫数据框单元格中存储稀疏向量的最佳方法是什么?
- java - (Android Studio) 不能在 Fragment 中使用 context/getActivity()
- shopware - 如何在 shopware6 中本地化自定义控制器的路由