Link to home
Start Free TrialLog in
Avatar of Pau Lo
Pau Lo

asked on

Select-String powershell advice

I found a usefulPowerShell script online (full code below) which helped me review an enormous txt file (log file) for rows containing a key word phrase and output just those rows to a txt file. What I could do with is a way of amending the $pattern row below:

$pattern = ‘searchterm’

Open in new window search another text file I have created which contains for a number of search terms I have put together, rather than me having to run the command for every search phrase I need to check individually.

full code:

$inFile = '\\server\share\directoruy\file.txt'
$outFile = '\\server\share\directoruy\hits.txt'
$pattern = ‘searchterm’
Select-String -Path $inFile -SimpleMatch $pattern | Select-Object -ExpandProperty Line | Set-Content -Path $outFile

Open in new window

for info the format of the text file I have created for using is just in a row by row format, e.g

Avatar of oBdA

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial