如何在多个文件中搜索字符串并在Powershell中返回文件名? [英] How to search a string in multiple files and return the names of files in Powershell?

查看:50
本文介绍了如何在多个文件中搜索字符串并在Powershell中返回文件名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几天前我开始学习 powershell,但我在 google 上找不到任何可以满足我需要的东西,所以请耐心回答我的问题.

I have started learning powershell a couple of days ago, and I couldn't find anything on google that does what I need so please bear with my question.

我被要求将一些文本字符串替换为多个文件.我不一定知道可能的目标文件的扩展名,我也不知道它们的位置.到目前为止,我已经设法递归浏览到目录 (get-ChildItem -recurse) 并找到我正在寻找的字符串 get-content 和 select-string:

I have been asked to replace some text strings into multiple files. I do not necessarily know the extension of the possible target files and I don't know their location either. So far I have managed to recursively browse into the directory (get-ChildItem -recurse) and find the string I was looking for with get-content and select-string:

Get-ChildItem -recurse | Get-Content | Select-String -pattern "dummy"

问题是,我可以看到我正在寻找的文本的出现,但我不知道如何告诉 PS 返回每个匹配文件的路径和名称.

The problem is, I can see the occurences of the text I am looking for, but I don't know how to tell PS to return the path and the name for every matching files as well.

如何获取包含我要查找的表达式的文件的名称和位置?

How can I get the name and location of the files that contains the expression I am looking for?

推荐答案

这应该给出包含您的模式的文件的位置:

This should give the location of the files that contain your pattern:

Get-ChildItem -Recurse | Select-String "dummy" -List | Select Path

这篇关于如何在多个文件中搜索字符串并在Powershell中返回文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆