Skip to content

Instantly share code, notes, and snippets.

@JohnL4
Last active December 14, 2023 15:00
Show Gist options
  • Save JohnL4/38f9b639be33bffcbbeb4cce3df29e04 to your computer and use it in GitHub Desktop.
Save JohnL4/38f9b639be33bffcbbeb4cce3df29e04 to your computer and use it in GitHub Desktop.
Find/grep for files that contain MULTIPLE strings (Boolean AND)
ls -rec | ? {$_ -is [IO.FileInfo]} `
| ? {(cat $_ | sls '\bALTER\s+TABLE\b' -list).Count -gt 0} `
| ? {(cat $_ | sls '\bADD\s+CONSTRAINT\b').Count -gt 0}
#### Older, more complicated cmd line follows:
ls -rec | ? {-not (HasNulls $_)} | ? {$_ | sls 'vital.?sign' -list} | sls 'critical' -list | ogv
# OR... (to post-process to filter OUT some spurious matches)
ls -rec | ? {(-not (HasNulls $_))} | sls 'session.*visitguid' | ? {-not ($_.Line -match 'session.*visitguid["\] ]*[=!]=')} | ogv
<#
Last clause is different from preceding 'sls' clauses in that it actually shows the found string. You might
want to structure it so that a bunch of clauses filter for the various strings and then have a last "show all hits"
sort of clause that searches for the strings again in a big compound regex.
PS C:\work\sxa\main\Components\EmergDept# gcm ls,gcm,sls,ogv
CommandType Name Version Source
----------- ---- ------- ------
Alias ls -> Get-ChildItem
Alias gcm -> Get-Command
Alias sls -> Select-String
Alias ogv -> Out-GridView
HasNulls is a command I wrote that looks for nulls in the first page (?) of the file so you don't wind up searching DLLs
and other binaries. See https://github.com/JohnL4/PowerShell/blob/master/HasNulls.ps1
#>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment