Powershell 获取内容中的多重匹配

标签 powershell robocopy

我想看看是否有任何行包含“较新”和/或“新文件”一词。我尝试过如下脚本,但没有运气。任何见解将不胜感激。

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


------------------------------------------------------------------------------

最佳答案

如果您使用 Get-Content 将该文件加载到 $InStuff 中,则可以使用 -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 获取内容中的多重匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59480526/

相关文章:

powershell - Powershell 3.0:COPY-ITEM筛选器或包含选项不起作用

powershell - 从 PowerShell 执行控制台应用程序

powershell - 如何在 PowerShell 中从管道中分块项目?

robocopy 错误,错误 32 (0x00000020)

directory - 如何复制名称中带有空格的目录

variables - PowerShell,Robocopy和SchTasks->发送命令的变量和文本

performance - 需要帮助提高 PowerShell 分隔文本解析脚本的性能

powershell - RoboCopy 来源

powershell - 从 robocopy 日志中删除百分比

powershell - 如何设置 $env :PATH in powershell