Extract Content

Pattern Match

find /i "keyword" file.txt

Find text, case-insensitive.

sls -path [file] -pattern [string]

Find strings in a file (PowerShell)

select-string -path [file] -pattern [string]

Find strings in a file (PowerShell)

Select-String -path c:\\users \\\*.txt –pattern password

Find strings in a file (PowerShell)

findstr "pattern" C:\path\to\file.txt

Find matching lines (CMD)

type C:\path\to\file.txt | findstr "pattern"

Find matching lines (CMD)

Get-Content file.txt | Select-String -Pattern "keyword"

Find strings in a file (PowerShell)

Find text within a file:

gci -recurse c:\\users -file | % {Select-String -path $ \_ -pattern password}

Search a file's contents for Polo. This also splits the file from one line to a newline for each word:

((Get-Content .\countpolos).split(" ")) | select-string \bpolo\b 

Filter lines that contain a specific string:

Get-Content C:\path\to\file.txt | Where-Object { $_ -match "specific string" } | Set-Content C:\path\to\filteredfile.txt

Don't forget to use -ErrorAction SilentlyContinue

Line Numbers

Displays the content of a file starting from the 11th line:

Unique / Deduplicate

Remove duplicate lines from a file:

Reads the file, sorts the lines, removes duplicates, and saves the result to a new file using PowerShell.

Filters lines matching a specific pattern, removes duplicates, and saves to a new file using PowerShell.

For CSV files, sorts entries based on a specific column, removes duplicates, and saves the result to a new CSV file using PowerShell.

Groups lines, identifies duplicates, selects one occurrence of each duplicate, and saves the result using PowerShell.

Last updated

Was this helpful?