What is the mos easy/comfortable way to use Powershells built-in functions to emulate grep like behaviour?
In scripts I use something like this
dir "*.filter" | foreach-object{
$actfile = $_
$readerrorfile = [System.IO.Path]::GetTempFileName()
$found = $false
$content = Get-Content $actfile 2> $readerrorfile
$readerror = Get-Content $readerrorfile
if($readerror -match "Error"){
echo "Error while reading from file $actfile"
echo $readerror
del $readerrorfile
Write-Host "stopping execution"
exit
}else{
del $readerrorfile
if($content -match "keyword|regex"){
echo "found in $actfile"
$found = true;
}
}
}
I fairly sure there is an easier/shorter version for that, maybe a one-liner. So, what is the best way to it the grep way?