I need to report keyword occurrence using grep with power-shell and export the result in csv format if possible.
I need command similar to this one (it doesn't work for me in powershell)
cat .\PlaySound.txt | grep "Keyword" | grep $(date --date="@$(($(date +%s) - 3600))" "+%d/%b/%Y:%H") | wc -l
For exemple:
I'm assuming the main issue is generating and formatting the timestamp?
In PowerShell, the equivalent would be:
Get-Date (Get-Date).AddHours(-1) -UFormat "+%d/%b/%Y:%H"
So to recreate the whole pipeline we can do something like this:
$timestamp = Get-Date (Get-Date).AddHours(-1) -UFormat "+%d/%b/%Y:%H"
Get-Content .\PlaySound.txt |Where-Object {$_ -match 'Keyword' -and $_ -match $timestamp} |Measure-Object -Line |Select-Object -Expand Lines