PowerShell May Be Better on Posix

(Comments)

After something being wayyyy easier than I thought it was going to be, I’m ready to claim that PowerShell is better when not used on Windows. I submit the following 1-liner as evidence:

gc user.ldif | % { [Regex]::Match($_,'[a-zA-Z]+(?=:)').ToString() } | ? { [bool]$_ } | sort | uniq > userprops.txt 

So it’s reading in a file, performing a regex on each line, filtering out the empty lines…. now it gets interesting. I did a ‘sort -Unique’ and it gave an error, sort isn’t an alias to Sort-Object on Linux. It's using GNU sort without having to explicitly convert from the object pipeline to bash pipe. Then it’s piping that to GNU uniq, then using the shell’s redirection to write out to a file, no Out-File business. Yep, I think PowerShell is better when not used on Windows.

Currently unrated

Comments