/\/\o\/\/ PowerShelled

This blog has moved to http://ThePowerShellGuy.com Greetings /\/\o\/\/
$AtomFeed = ("Atom.xml")
$PreviousItems = (" PowerShell Active Directory Browser teaser "," Powershell, Has my Dell a dangerous battery Part 2 ? "," PowerShell, Has my Dell a dangerous battery ? "," PowerShell Adding -verbose switch to functions "," PowerShell and Active Directory Part 9 (nested gro... "," Powershell and hey Scripting guy ! "," PowerShell Orphan share remover Tool (Update) "," PowerShell and Active Directory Part 8 (ACL's) "," Signing PowerShell Scripts "," PowerShell and Active Directory Part 7 "," ")

Saturday, September 02, 2006

 


PowerShell : How can I tell whitch numbers are missing from a sequence of numbers found in a text file ?



 Another Hey Scripting Guy ! Question I could not refuse ;-)

How Can I Tell Which Numbers Are Missing From a Sequence of Numbers Found in a Text File? In Powershell ?

let’s make a text file containing the following sequence of numbers:

 

# Make a TextFile with the Numbers

@'
2
4
8
9
10
'@ | sc test.txt

 

How are we going to determine which numbers (1, 3, 5, 6, and 7) are missing from the sequence? Like this:

gc test.txt |% {$i = 1}{while ($i -lt $_){$i;$i++};$i++}

 

PoSH>gc test.txt |% {$i = 1}{while ($i -lt $_){$i;$i++};$i++}
1
3
5
6
7

What’s that? Explain how this script works? Come on, SG; didn’t we mention that it was Saturday?

*Edit* did I hear someone say Sort ? (thx Karl)

*Edit2* Added from file with cast to INTEGER

gc test.txt | sort {[int]$_} |% {$i = 1}{while ($i -lt $_){$i;$i++};$i++}

PoSH>2,9,4,8,10 | sort |% {$i = 1}{while ($i -lt $_){$i;$i++};$i++}
1
3
5
6
7

 

*Edit3*, Ok, still no explanation but this might help understanding how this script works :  PowerShell : Can you do that less cryptic ?

Enjoy,

Greetings, /\/\o\/\/
Tags : Monad msh PowerShell




Comments: Post a Comment



<< Home

Archives

October 2005   November 2005   December 2005   January 2006   February 2006   March 2006   April 2006   May 2006   June 2006   July 2006   August 2006   September 2006   October 2006   November 2006   December 2006  

$Links = ("PowerShell RC1 Docs"," PowerShell RC1 X86"," PowerShell RC1 X64"," Monad GettingStarted guide"," Monad Progamming Guide"," Monad SDK"," Monad videos on Channel 9"," MSH Community Workspace"," scripts.readify.net "," MonadSource"," www.reskit.net"," PowerShell Blog"," Under The Stairs"," computerperformance powershell Home"," proudlyserving"," MSH on wikipedia"," MSHWiki Channel 9"," Keith Hill's Blog"," Precision Computing"," PowerShell for fun"," MSH Memo (Japanese)"," monadblog")

find-blog -about "PowerShell","Monad" | out-Technorati.
find-blog -contains "","" | out-Technorati.
Google
 
Web mow001.blogspot.com

This page is powered by Blogger. Isn't yours?