Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

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.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Removing lines from a text file by matching against substrings

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
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
Closed Thread

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


Vistax64.com 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 2005-2008

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 47 48 49 50 51