要验证文本文件中存在某些字符串,请发送警告,如果没有,请发出警告

发布于 2025-02-13 13:01:45 字数 380 浏览 1 评论 0 原文

我有一个过程,其中包含数据的文件是在单独的位置生成,保存到网络位置并合并到一个文件中的过程。

在过程的结束时,我想检查该合并文件中是否存在所有位置,并通知我。

我遇到了一个问题,可以找到一种方法来识别不存在特定于每个位置的字符串,即在if语句中使用,但似乎无法正确识别字符串?

我已经尝试过:

get-childitem -filter *daily.csv.ready \\x.x.x.x\data\* -recurse | where-object {$_ -notin 'D,KPI,KPI,1,'}

我知道如果存在的话,什么都不做可能更容易,如果没有,请执行警告措施,但是我很好奇是否可以在反面中完成此操作。

谢谢你,

I have a process where files containing data are generated in separate locations, saved to a networked location, and merged into a single file.

And the end of the process, I would like to check that all locations are present in that merged file, and notify me if not.

I am having a problem finding a way to identify that a string specific to each location isn't present, to be used in an if statement, but it doesn't seem to be identifying the string correctly?

I have tried :

get-childitem -filter *daily.csv.ready \\x.x.x.x\data\* -recurse | where-object {$_ -notin 'D,KPI,KPI,1,'}

I know it's probably easier to do nothing if it is present, and perform the warning action if not, but I'm curious if this can be done in the reverse.

Thank you,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

太阳男子 2025-02-20 13:01:45

AS doug Maurer 指出,您的命令确实 not 通过 content搜索 get-childitem get-childitem 因为那个cmdlet发出的是 system.io.fileinfo (或者,可能, system.io.directoryInfo )包含有关匹配文件(目录)而不是其的实例内容

换句话说: $ _ 变量在您的 where-object where-object 到对象描述的文件而不是其内容。

但是,您 can pipe system.io.fileinfo 实例 select-string cmdlet,确实搜索输入文件' content

Get-ChildItem -Filter *daily.csv.ready \\x.x.x.x\data\* -Recurse | 
  Where-Object { $_ | Select-String -Quiet -NotMatch 'D,KPI,KPI,1,' }

As Doug Maurer points out, your command does not search through the content of the files output by the Get-ChildItem command, because what that cmdlet emits are System.IO.FileInfo (or, potentially, System.IO.DirectoryInfo) instances containing metadata about the matching files (directories) rather than their content.

In other words: the automatic $_ variable in your Where-Object command refers to an object describing a file rather than its content.

However, you can pipe System.IO.FileInfo instances to the Select-String cmdlet, which indeed searches the input files' content:

Get-ChildItem -Filter *daily.csv.ready \\x.x.x.x\data\* -Recurse | 
  Where-Object { $_ | Select-String -Quiet -NotMatch 'D,KPI,KPI,1,' }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文