It is uncommon for a Linux administrator to be unfamiliar with grep, sed, and awk. PowerShell has similar functionalities built in, although these cmdlets and operators deal with text as objects, rather than as plain strings. There are little nuances that we would need to remember when working with PowerShell. In this recipe, we will look at searching for content in files from within PowerShell. The Select-String cmdlet, our string-related operators, such as like and match, and the object-based pipeline collectively help us with this.
Imagine you have a collection of markdown files. These files contain PowerShell code blocks. You have to perform the following steps:
- Find the PowerShell code blocks present in the files within the directory. Show the filename, the line number, and the match, each on a separate line.
- Contextually show what each of those code...