![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #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 | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Return the next line of in a text file after matching the previous | PowerShell | |||
| Using lines in a text file | PowerShell | |||
| Howto: Add lines of text from a specific point in a text file.. | VB Script | |||
| Removing lines from a text file | PowerShell | |||
| removing first three lines in a text file | PowerShell | |||