5 ms·
Which is fine when you're starting out, but infinitely frustrating after you have an idea of what you're doing. A recent example, looking for errors in windows
by Karunamon 11y ago
Which is fine when you're starting out, but infinitely frustrating after you have an idea of what you're doing.
A recent example, looking for errors in windows logs:
Get-Childitem "C:\Windows\" -recurse -Include *.log ` | Select-String "Error" -ErrorAction SilentlyContinue ` | Group-Object filename | Sort-Object count -descending
Closest *NIX analogue I can think of would be
grep -r Error /var/log/ | sort
English is an arguably fine speaking language but an awful programming one.
I love what Powershell can do, but gods do I hate typing it.
- Touche 11y agoI'd also wager Select-String is an order of magnitude slower than grep or ag.
- RamseyMcGrath 11y agoYou'd be wrong (at least for grep) http://www.jwgoerlich.us/blogengine/post/2013/01/21/Grep-versus-Select-String-Speedtest.aspx http://www.jwgoerlich.us/blogengine/post/2013/01/21/Grep-ver...
- kuschku 11y agoExcept, GNU grep is even faster than Select-String, if you run it on a better filesystem.
- r-w 11y agoTry links and environment variables to substitute long commands and flags, respectively. Fine, it’s not there by default, but as a power user you have the ability to adapt it to your needs. (That would also be a cool fix to release on GitHub for others like you to use as well. Yay hackability!)
- mpweiher 11y agoRight. When I found out that this was supposed to be the alternative, I almost lost it. For the thing to become usable, you have to do personal configuration, meaning your system will be unusable to anyone else and theirs will be unusable to you. Back to the drawing board...
- overgryphon 11y agoLots of powershell cmdlets have aliases too. They are less discoverable than the verb-noun names, but for cmdlets I use often they are great. Get-ChildItem is aliased to gci, ls, and dir.
- Someone1234 11y agoThose two lines do different things. They're not analogous. The equivalent to the UNIX line above in Powershell is: ls "C:\app\*.log" -R | sls "Error" | sort You cannot just tack on a bunch of extra requirements for Powershell (grouping, sorting by certain things and in a certain order) and then not include them in the UNIX example, that's disingenuous/misleading. The only big difference between PS and UNIX in an actual analogous example is that the PS version of grep gets files fed in one by one and processes them, whereas UNIX's grep processes files itself. PS - The above Powershell code may not work in 2.0 (2009). You'll need 3.0 (2012) or higher.
- Karunamon 11y agoHence "I can think of". That was copypasta from an internal wiki. I don't appreciate being accused of "disingenousness" from an off the cuff example. By the way, your example is precisely 12 characters longer than mine and still multiple times shorter than the equivalent PS, so if your goal was to somehow disprove PowerShell's annoying verboseness rather than snark at me, you failed.
- togusa 11y ago(iwr "http://Slashdot.org").Links | select href Nearest Unix equivalent please.
- kuschku 11y agoWhat does that even do? Sorry, I’m not familiar with Windows, but would love to provide a unix equivalent.
- Arnavion 11y agoFetches http://Slashdot.org http://Slashdot.org (`iwr ...`), parses it as an HTML page and extracts all the anchor tags (`.Links`), and selects the href of each anchor tag (`select href`). Since this is the end of the command, the hrefs are returned and printed as an array of strings (so one href on each line).
- ckozlowski 11y agoI'd agree it's a bit more to type out, but it does seem to make more sense from a readability perspective. And for those of us who didn't grow up with the UNIX shell to understand the reasons why things were kept so short, it's a bit easier to digest. (I do appreciate why bash is so short and succulent. =) But really, taking the above into consideration, the might in powershell comes not from the terms used, in my opinion, but how it works on things. With grep for example, you're parsing a file. If say, you wanted to filter on that more, you'd be using awk to pick out parts of the text. In Powershell, everything's an object. Everything's already an object, you don't need to pick the file apart to isolate the date, you just filter on the date object. It's got a data type. That makes it really powerful, in my opinion. (Example largely pulled from "Windows Powershell in Action". I really like this book, as it goes into detail to describe /why/ things are they way they are in PowerShell, because he wrote it. =) https://www.manning.com/books/windows-powershell-in-action-second-edition https://www.manning.com/books/windows-powershell-in-action-s...
- dpark 11y ago> but it does seem to make more sense from a readability perspective Not really, as everything is given an unreadable alias anyway, and many are given multiple aliases: Copy-Item -> copy,cp,cpi. So there are just more names to learn.
- ckozlowski 11y agoYou don't have to use the aliases though, and they don't tab complete (only the full name does) Personally, I never use them. I saw them more as a help for people coming over from bash.
- dpark 11y agoYou do have to use them unless you work alone. I regularly see PS1 files that use the various aliases, as well as the fully-named commands.