Created
April 4, 2010 22:18
-
-
Save johnnyhalife/355749 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$INTIAL_SPACE = 5 | |
# On the hosts file use the same spa cing between entries using | |
# 7 as the constant spaces between "words" but compensating length | |
function tabulate { | |
$longest, $source = 1, $args[0] | |
$contents = (gc $source) | |
#find the longest word | |
clear-content $source | |
$contents | %{ [regex]::match($_, "^[^#](\S+)\s*(\S+).*$").Groups[1].Value } | %{ if($_.length -gt $longest) { $longest = $_.length } } | |
$contents | where-object {[regex]::match($_, "^([^#\s]+)\s*(\S+).*$").success -eq $false } | add-content $source | |
# add the contents to da file | |
$contents | | |
%{[regex]::match($_, "^([^#\s]+)\s*(\S+).*$") } | | |
where-object { $_.success -eq $true } | | |
%{($_.Groups[1].Value + (new-object String " ", ($longest - $_.Groups[1].Value.Length + $INTIAL_SPACE)) + $_.Groups[2].Value).trim() } | | |
add-content $source | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment