Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

How can I use select-string to only output last phrase in file

$
0
0

So I'm trying to run a script that searches a particular file for the phrase "Default Printer:     PRINTERNAME". What I have so far is:

cls

$file = "c:\temp\print.log"

Select-String -pattern "Default Printer:..." -path $File

This is returning a lot more data than I'd like:

c:\temp\print.log:864:9/9/2014 10:01:18 PM:  Default Printer:  HEIAISNF004
c:\temp\print.log:890:9/10/2014 8:27:08 AM:  Default Printer:  HEIAISNF004
c:\temp\print.log.log:944:9/11/2014 8:06:45 AM:  Default Printer:  HEIAISNF004
c:\temp\print.log:1012:9/12/2014 7:51:15 AM:  Default Printer:  HEIAISNF004
c:\temp\print.log:1108:9/16/2014 7:38:20 AM:  Default Printer:  HEIAISNF004
c:\temp\print.log:1134:9/18/2014 8:42:46 AM:  Default Printer:  HEIAISNF004
c:\temp\print.log:1244:9/24/2014 4:55:44 AM:  Default Printer:  HEIAISNF004

I only want the last instance of the pattern (which happens to be the most recent), and I want to output the value (in this case HEIAISNF004) to a csv file.

Any ideas on how I can do that?


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>