0

I was looking at this other question, but wasn't sure how to combine these queries together.

I started off with this, but it doesn't seem to work:

findstr /S /M "string A" *.vb | findstr /S /M /V "string B" > output.txt

For example, I want to get a list of files containing "string A" but NOT "string B".

I would like to use the Windows command line if possible or Windows PowerShell.

2
  • I know that you have a pereference for cmd, but powershell is sitting right there on your machine from Windows7 on and can be installed for prior versions too. Since you expressed that preference though I will give this as a comment instead of an answer: ls .\*.vb | Select-String A | Select-Object path -unique | Where-Object{!(Select-String -InputObject $_ -Pattern B)}
    – EBGreen
    Commented Jun 18, 2018 at 15:30
  • @EBGreen I will change my question to also allow for PowerShell responses so you can post as an answer. I'm not getting any results, however. Does this search subfolders? Commented Jun 18, 2018 at 15:43

1 Answer 1

1

This should do it in powershell:

Get-ChildItem .\*.vb | Select-String A | Select-Object path -unique | Where-Object{!(Select-String -InputObject $_ -Pattern B)}

To include Sub-Folders:

Get-ChildItem .\*.vb -Recurse | Select-String A | Select-Object path -unique | Where-Object{!(Select-String -InputObject $_ -Pattern B)}

I'm not positive what makes your specific example different from my mock up, but using your specific search terms try this:

Get-ChildItem .\*.vb -Recurse | Select-String HttpDelete | Select-Object path -unique | Where-Object{!(Select-String -InputObject (Get-Content $_.Path) -Pattern securityEntityPermission)}
4
  • This seems to find files containing the "A" string ok, but isn't also excluding files that contain the "B" string (if they contain the "A" string). Commented Jun 18, 2018 at 16:12
  • Yeah, so I dummied up a test scenario with 6 files. Two had A in them but no B. Two had B in them but no A. Two had A and B in them. What I posted returned just the two with only A. What are you actually executing?
    – EBGreen
    Commented Jun 18, 2018 at 16:22
  • I'm running this from the directory I want to execute it on: Get-ChildItem .*.vb -Recurse | Select-String "HttpDelete" | Select-Object path -unique | Where- Object{!(Select-String -SimpleMatch -InputObject $_ -Pattern "securityEntityPermission" )} It still seems to be returning me files that have securityEntityPermission in the files themselves when I don't want these files to be returned. I tried using the application Agent Ransack, and was able to get the correct files, so I'm not sure why this isn't working. Commented Jun 18, 2018 at 18:54
  • Check the edit.
    – EBGreen
    Commented Jun 18, 2018 at 19:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .