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 blank lines?

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 02-15-2007   #1 (permalink)
Nikhil R. Bhandari
Guest


 

Removing blank lines?

How to eliminiate the blank lines from log file?
Can it be done through regular expressions /^$/

Thanks,
Nikhil



My System SpecsSystem Spec
Old 02-15-2007   #2 (permalink)
mikes.net
Guest


 

Re: Removing blank lines?

> How to eliminiate the blank lines from log file?
> Can it be done through regular expressions /^$/


There is a way I often see used but it doesn't work if some of the
"empty lines" happen to have whitespace:

PS > gc Test.txt | select-string .

Here is a way that does seem to work:

PS > gc Test.txt | ? { $_ -notmatch "^$|^\s+$" }
One The next line is blank
Two Next, a line that has three spaces and three tabs
3 987 654
,%~` !@$!@#$
Five And this is the end.
PS > gc Test.txt

Mike

My System SpecsSystem Spec
Old 02-16-2007   #3 (permalink)
Keith Hill [MVP]
Guest


 

Re: Removing blank lines?

"mikes.net" <michael.net@gmail.com> wrote in message
news:1171547571.724191.316310@v45g2000cwv.googlegroups.com...
>> How to eliminiate the blank lines from log file?
>> Can it be done through regular expressions /^$/

>
> Here is a way that does seem to work:
>
> PS > gc Test.txt | ? { $_ -notmatch "^$|^\s+$" }
> One The next line is blank


I think that the regex could be simplified to '^\s*$'.

--
Keith


My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Blank lines at top of reply Joseph Meehan Live Mail 1 05-18-2008 12:53 PM
Blank lines at top of reply Joseph Meehan Live Mail 0 03-28-2008 06:22 AM
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
editing subject lines and removing attachments eric Vista mail 1 11-09-2006 09:17 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