Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista Tutorial - Removing lines from a text file by matching against substrings

Reply
 
Old 02-15-2007   #1 (permalink)
Bill V.
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 right
logic?)

My System SpecsSystem Spec
Reply

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46