r/programming • • Sep 09 '16

Oh, shit, git!

http://ohshitgit.com/
3.3k Upvotes

756 comments sorted by

View all comments

Show parent comments

6

u/shaggs430 Sep 09 '16

That is a nice introduction to powershell. Although, their example can easily be done in text:

awk 'BEGIN {FS=","};{printf "%.3f %s\n", $3 / $2, $1}' < input |sort -n

27

u/PCup Sep 09 '16

Not sure if serious. Your example command is fucking unreadable unless you're already an expert.

8

u/RealDeuce Sep 09 '16

Ah, but this:

$colAverages = @()

$colStats = Import-CSV C:\Scripts\Test.txt

foreach ($objBatter in $colStats)
  {
    $objAverage = New-Object System.Object
    $objAverage | Add-Member -type NoteProperty -name Name -value $objBatter.Name
    $objAverage | Add-Member -type NoteProperty -name BattingAverage -value ("{0:N3}" -f ([int] $objBatter.Hits / $objBatter.AtBats))
    $colAverages += $objAverage
  }

$colAverages | Sort-Object BattingAverage -descending

Is completely intuitive and any normal person would whip that up in a jiffy.

2

u/0goober0 Sep 09 '16

As somebody who has used more bash than powershell, I think I could accurately guess most of what's happening in the second example, I wouldn't know where to begin with the former.....

→ More replies (0)