0

I am a novice and have been tasked to extract data from a bunch of text files. I have managed to put together some very simple PowerShell code (seen below) that does most of the work. However, the Line object is truncated in the output file and I was wondering if there was a way I could modify the code to (by using Select-Object -ExpandProperty Line?) but not sure how to incorporate it with the rest of the script. Here is the code...

Select-String -Path "C:\Users\*.txt" -Pattern "reduce", "increase", "cease", "stop" -Context 2 | Select-Object Filename, Pattern, LineNumber, Line| Out-File "C:\Users\Recommendations_inital.txt"

Any assistance is very much appreciated!

Santiago Squarzon
  • 41,465
  • 5
  • 14
  • 37
Adrian
  • 1
  • 1
    [1] please add code formatting markers around your code. you can find how to do that on the page that you used to create your Question OR on the `tour` page for this site. ///// [2] add to your Question [wrapped in formatting markers] the output you are getting, the output you expect, AND the input string that produced the output you actually got. – Lee_Dailey Feb 16 '22 at 02:28
  • 2
    I believe your problem would be solved if you were to output to a CSV using `Export-Csv` instead of `Out-File`. In that case you would end up with cells with multi-line strings – Santiago Squarzon Feb 16 '22 at 02:28
  • Thank you for the update, Lee_Dailey. My apologies, I'm fairly new at this and hadn't realised. It appears someone has already done this for me. Many thanks to whoever did so! Also, Many thanks Santiago Squarzon! I knew it was a simple fix and I'm grateful you were able to help out. Do you recommend and resources or courses that would help to build my competency in Powershell language? – Adrian Feb 19 '22 at 08:03

0 Answers0