Finding a string in PowerShell

code
Notes when working on bmd
Author

Zhenglei Gao

Published

July 2, 2025

Finding AIC.drcHetVar in PowerShell

To find a specific file or function in your codebase using PowerShell, you can use several commands. Here are different approaches to find “AIC.drcHetVar” in your repository:

1. Find in File Names

# Find files with AIC.drcHetVar in the name
Get-ChildItem -Path . -Recurse -File | Where-Object { $_.Name -like "*AIC.drcHetVar*" }

2. Find in File Contents

# Search for "AIC.drcHetVar" in all files
Get-ChildItem -Path . -Recurse -File | Select-String -Pattern "AIC\.drcHetVar"

3. Search in R Files Only

# Search only in R files
Get-ChildItem -Path . -Recurse -File -Include "*.R" | Select-String -Pattern "AIC\.drcHetVar"

4. Search with Context

# Search with surrounding lines for context
Get-ChildItem -Path . -Recurse -File -Include "*.R" | Select-String -Pattern "AIC\.drcHetVar" -Context 2,2

5. Find Function Definition

# Look specifically for function definition
Get-ChildItem -Path . -Recurse -File -Include "*.R" | Select-String -Pattern "AIC\.drcHetVar\s*<-\s*function|AIC\.drcHetVar\s*=\s*function"

6. Search in Documentation Files

# Search in Rd files
Get-ChildItem -Path . -Recurse -File -Include "*.Rd" | Select-String -Pattern "AIC\.drcHetVar"