![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | Removing lines from a text file by matching against substrings Hello everyone. I'm approaching this as my first powershell script in trying to both accomplish something and learn a little powerscript in the process. Basically I have a decently sized syslog file that I would like to parse through and remove entries from as I recreate the file. My logfile is a listing of logins to a group of computers and I want to remove the automated logins and just see the more interesting ones of people sitting down and using them. And to be even more ambitious, I'm trying to accomplish this in a filter so help speed things along a bit and save on some memory as well. The code I have so far is this: filter filter-Exclude { Param ($Remove) $result = $_ foreach ($Remove in $ExcludeAry) { if (Select-String -pattern $Remove) { $result = $null } } $result } $Exclude = Get-Content .\Exclude.txt #New-Item .\results.txt -type file Get-Content .\CatchAll.txt | filter-Exclude $Exclude Exclude.txt has the keywords that I want to strip out of the logfile and catchall.txt is the logfile itself. Since I can't figure out how to have Select-String return strings that don't match the results, I'm trying to go the other way and change a positive match to a null so I can write this to the file without adding additional logic to skip writing it to the file. And, I should add, I'm not writing to the file right now - my results.txt file - simply because I haven't gotten things to work right to the console. Does this make sense? Anyone see a better way to do things (well, working would be better , but I mean "am I not approaching this with the rightlogic?) |
My System Specs![]() |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Using lines in a text file | tERRY | PowerShell | 3 | 08-01-2008 08:54 AM |
| Howto: Add lines of text from a specific point in a text file.. | Daz | VB Script | 13 | 06-24-2008 10:55 AM |
| get the number of lines in a text file | Jason1008 | PowerShell | 2 | 06-12-2008 09:41 PM |
| Removing lines from a text file | Did | PowerShell | 3 | 03-15-2007 09:38 AM |
| removing first three lines in a text file | fixitchris | PowerShell | 2 | 11-17-2006 06:21 PM |