Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Extract text and numeric values from a text file

$
0
0

 

I’m new to powershell regular expressions and have a question on how to write one that would extract text and numeric values from .txt log files. Here is a sample of the log file.

Note: There are no spaces between the string lines in the original file:

 

"4/30/2012 10:47:03 AM","1","About","SyncBackPro V6.0.12.0 Log",0,"O"

"4/30/2012 10:47:03 AM","1","Profile Name","Test Backup - 1",0,"O"

"4/30/2012 10:47:03 AM","1","Type","Mirror Right",0,"O"

"4/30/2012 10:47:10 AM","1","Deleted","2",0,"O"

"4/30/2012 10:47:10 AM","1","Skipped","4",0,"O"

"4/30/2012 10:47:10 AM","1","Copied","2",0,"O"

"4/30/2012 10:47:10 AM","1","Copied/Moved","0.07KBytes",0,"O"

"4/30/2012 10:47:10 AM","1","Scan Started","4/30/2012 10:47:04 AM",0,"O"

"4/30/2012 10:47:10 AM","1","Scan Finished","4/30/2012 10:47:04 AM",0,"O"

"4/30/2012 10:47:10 AM","1","Profile Start Time","4/30/2012 10:47:03 AM",0,"O"

"4/30/2012 10:47:10 AM","1","Profile End Time","4/30/2012 10:47:10 AM",0,"O"

"4/30/2012 10:47:10 AM","1","Result","Success",0,"O"

 

So far I was able to extract just the lines of text that are of importance and output them into a single file.

Get-Content $file | Select-String -pattern "Profile Name", "Deleted", "Skipped", "Copied", "Copied/Moved", "Profile End Time", "Result" | Out-File $logpath -encoding ASCII -append

   }      ## part of the script's function.

To make the summary report look more readable I need to extract just the values that follow those pre-define text patterns.  I only need the values that are highlighted. They follow certain text patterns  that don’t change: “Profile Name”, "Deleted", "Skipped", "Copied",  "Copied/Moved", "Profile End Time", "Result" . The numeric values that follows "Deleted", "Skipped", "Copied" or "Copied/Moved" could be any number in 0 - 50,000 range.

Please help!

Thanks,

Paul Leskov

 

 

 

 

 

 

 

 

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles