Quantcast
Channel: PowerShell
Viewing all articles
Browse latest Browse all 15370

Powershell - Regex log files

$
0
0

Maybe I'm going about this wrong. I have a log file that contains Date, Time, Name. I can use a regex for each to find the data in a line of text:

Powershell
$regdt='\b\d{1,2}\/\d{1,2}\/\d{1,4}\ \d{1,2}\:\d{1,2}\:\d{1,2}\b'$regtime='\d{1,2}\:\d{1,2}\:\d{1,2}\b'$regnm='\w+\ \w+\ * \(\w{2,}\)'

This obviously outputs each match from each line. However, I would like for them all to output with the other data from the line. For example, my incoming text looks like this:

Text
log:221:11/23/19 15:56:07.372 S I [T-16136] - HTTP UserMgr: Start User login notify for user: Bob Smith (Home) log:248:11/23/19 16:56:07.950 S I [T-16136] - User Logout: Bob Smith (Home) 

The output I am looking for is:

Text
11/23/19, 15:56:07, User Login, Bob Smith (Home) 11/23/19, 16:56:07, User Logout, Bob Smith (Home) 

I am using the following to Output:...


Viewing all articles
Browse latest Browse all 15370


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