我需要一个Powershell 脚本,它读取给定文件以查找关键字“匹配:”和“替换:”的任何出现,并将其前面的行复制到另一个文本文件中的新行,并用管道分隔并结束。下面的例子。
输入
20/01/2016 00:00:18 Some Lines of Text here
20/01/2016 00:00:18 Some Lines of Text here
20/01/2016 00:00:18 Match: /test/OLD/Myfolders/Folders/Folder1/
20/01/2016 00:00:19 Replace: /test2/NEW/currentfiles/
20/01/2016 00:00:19 Some Lines of Text here
20/01/2016 00:00:20 Some Lines of Text here
20/01/2016 00:00:20 Some Lines of Text here
20/01/2016 00:00:20 Match: /match/2015/pages/
20/01/2016 00:00:20 Replace: /replace/2016/pages/
20/01/2016 00:00:21 Some Lines of Text here
输出
/test/OLD/Myfolders/Folders/Folder1/|/test2/NEW/currentfiles/|
/match/2015/pages/|/replace/2016/pages/|
所以每次找到关键字“匹配:”时,它前面的 URL 都会被复制到新文本文件中的新行,然后是管道和“替换:”前面的 URL
/Matching URL/|/Replacing URL/|
/Matching URL/|/Replacing URL/|