I'm looking to see if Powershell can help me solve a common issue I come across dealing with a large code base / set of files.
In short I'm very frequently wanting to "grep" for files that contain a certain keyword or pattern... then (recursively) filter that set of files to those that (A) also include or (B) specifically do not include another keyword or pattern.
e.g.
Lets say that I have 300 PHP files that are all somewhere within a folder called "project_files". I'd like to find all files that contain "someInclude.php"... and also contain "specialFunction()"
Can I do this in one pass... e.g. pipe to pipe to pipe? or do I need to collect the list of file names in the first pass, then re-run the sub-query(/ies)
$results = Get-ChildItem -recurse -ErrorAction SilentlyContinue |
Select-String -pattern "someInclude.php"
(wrapped code for readability)
...this is where I'm stuck as to where to go next...
Can I iterate over my results? or do I need to write these to a file and read that file back in, searching in each file as I load it?