Skip to content

Instantly share code, notes, and snippets.

@stknohg
Last active February 15, 2017 10:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stknohg/0b43f3871462a428493d84a56921e314 to your computer and use it in GitHub Desktop.
Save stknohg/0b43f3871462a428493d84a56921e314 to your computer and use it in GitHub Desktop.
PowerShellのSort-ObjectコマンドレットIPアドレス(V4)をソートするサンプル
#
# https://orebibou.com/2015/05/linuxunixのsortコマンドでipアドレスのソートを行う/
# のPowerShell版
#
cat .\test.txt | sort (0..3|%{[ScriptBlock]::Create("[int]$`_.Split('.')[$_]")})
#
# version sort風(by @mutaguchi)
#
cat .\test.txt | sort {[version]$_}
192.168.0.102
192.168.0.8
192.168.0.97
192.168.0.68
192.168.0.99
192.168.0.66
192.168.0.24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment