Windows – Trying to take the line from a logfile, remove some text, and put it into a new text file in a batch script

batchscriptwindows 10

I am trying to take the last line from a logfile and remove some text from the beginning and end of it and put it into a new text file.
I have minimal batch experience, any help is appreciated.

last line:

Opening track for playback: "D:\Music\musicfile.m4a"

Path to the logfile:


What I want the last line to look like when it is done:


Best Answer



$LogFile = "$env:%USERPROFILE%\Documents\file.log"
(Get-Content -Path $LogFile | Select -Last 1) -match '.+\\([\w\s]+)\.\w{3}"$' | out-null

At the console:

(gc "$HOME\Documents\file.log")[-1] -match '.+\\([\w\s]+)\.\w{3}"$'

Alternate string manipulation:

$Line = (gc "$HOME\Documents\file.log")[-1]

or even a one-liner:

(gc "$HOME\Documents\file.log")[-1].split('"')[1].split('\')[-1].split('.')[0]



About Regular Expressions

Related Question