Live data from Hacker News

PowerShell is open sourced and is available on Linux

azure.microsoft.com

781–790 of 790 posts

Re: PowerShell is open sourced and is available on Linux

#781

Earlier quoted context omitted.

> You are considering it just RAW text when it is actually formatted text that has been parsable for years with common unix command line tools. Parsing command output with sed/awk/etc (ie. "common unix command line tools") is absolutely an ad hoc parser. Let me give you an example that I recently ran into. I have a tool that parses the output of "readelf -sW", which dumps symbols and their sizes. The output normally…

The Unix answer is why are you using a regex on tab-separated values? Wrong tool for the job. Of course the problem with Unix is that there are a thousand different semi-structured text formats, edge cases, and tools that must be mastered before you can make any sense of it all. Any time you point out the pain a Unix fan can just respond by pointing out your ignorance.

> The Unix answer is why are you using a regex on tab-separated values?

They aren't tab-separated. There are no tabs in readelf output.

Also if you assume they are space-separated, note that the first few lines look like this:

    Symbol table '.dynsym' contains 164 entries:
       Num:    Value          Size Type    Bind   Vis      Ndx Name
         0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
> respond by pointing out your ignorance.

Indeed.

Re: PowerShell is open sourced and is available on Linux

#782
post #413

Earlier quoted context omitted.

If all this API effort had gone into a real cross-platform language (Python, Ruby, or even Perl which was king in 2001), Windows would have flourished. They went for their traditional lock-in approach instead, so now they have to catch up.

Windows did flourish... And are you suggesting that Perl would have been a better solution for a Windows interactive shell and automation tool? Are you going for the more readable argument? Or the more strongly typed argument?

> Windows did flourish

Late reply, sorry. I don't think we're on the same page: Windows sold relatively ok, basically doing tying the battle for the Enterprise sector, but in the meantime it lost the cloud war and was literally wiped out of several other segments (mobile, web etc). But don't take it from me: if everything were hunky-dory, they wouldn't be busy steering like crazy towards opensource, something that was unthinkable 15 years ago.

> are you suggesting that Perl would have been a better solution for a Windows interactive shell and automation tool?

From a mindshare/commercial perspective, yes it would have been (and I say this as a complete Perl-hater). By starting from scratch, MS then had to spend a decade evangelising their new solution, with mixed results. It would have been tremendously easier to just offer first-rate support for established sysadmin tools (ssh, perl/python etc) from day 1; but again, don't take it from me: the big new Windows Server features are Ubuntu-bundling and native ssh support. This would not be necessary, were Powershell and Windows dominant from a commercial perspective.

Re: PowerShell is open sourced and is available on Linux

#783

Earlier quoted context omitted.

OK, but now imagine it's not a database, because there are programs that do act this way.

And those programs usually emit proper CSV. You could use regex to match on what you want, but AWK was literally built for this. It's fantastic, it works great, and if you don't use that tool that was built to solve your problem, that's your own lookout.

I don't think awk is actually capable of parsing CSVs in all cases.

Re: PowerShell is open sourced and is available on Linux

#784
post #667

Earlier quoted context omitted.

You can run streams of many millions of JSON objects pretty much as fast as the IO can feed it... most of the time, in situations like this, you're constrained by IO speed, not CPU... assuming you are working with a stream that has flow control. I tend to dump out data structures to line terminated JSON, and it works out really well for streams, can even gz almost transparently. Parse/stringify has never been the bot…

And just think how much faster it would be if there were no serialization and I/O involved at all...

And my method can work over distributed systems with network streams... There are advantages to streams of text.

Re: PowerShell is open sourced and is available on Linux

#785
post #110

Earlier quoted context omitted.

Powershell isn't competing with bash, it's competing with Python. So then, how does it compare against Python? While plenty of small scripts are still done with bash, I think Python is pretty common for serious production needs. I use it for virtually all scripting these days. I had a recent experience where a developer spent a day and couldn't get Powershell's webrequest library to do what he wanted. I was able to a…

Sure, there are different ways to do various things, especially depending on what one is familiar with and what the task at hand is. It sounds more like you knew how to get something done with your tools faster than the other guy/gal in this case. :)

There are obviously many factors such as domain knowledge and language familiarity. I respect the developer who failed to do this in Powershell, he's very capable.

In this case, I would chalk it up to Python having a longer history and being more mature. Neither of us were particularly familiar with this domain, but because of the quality of Python's online community and documentation, it wasn't difficult to accomplish the goal.

Re: PowerShell is open sourced and is available on Linux

#786
post #780

Earlier quoted context omitted.

DSV is the default format for many unix utils, and AWK and cut parse it easily.

Yes, of course; that is one end of the "middle ground" I described. The problem is that in Unix, there is no common convention for how to escape the delimiter, so you cannot pass arbitrary strings. CSV can do this, with the proper tooling. Being able to pass around arbitrary strings is quite valuable, and although it is not quite the same as passing objects around, it has the advantage of still being human-readable t…

Oh, you can pass arbitrary strings, you just can't pass arbitrary strings as part of compound datastructures. The closest you can get is using null or some other weird character to separate lines ($RS='\0' in awk), and something similar for field separation (like -0 in find, which is $FS='\0' in awk). But \0 is only one special character, so you need another one.

Re: PowerShell is open sourced and is available on Linux

#787

Earlier quoted context omitted.

And those programs usually emit proper CSV. You could use regex to match on what you want, but AWK was literally built for this. It's fantastic, it works great, and if you don't use that tool that was built to solve your problem, that's your own lookout.

I don't think awk is actually capable of parsing CSVs in all cases.

It doesn't parse escapes, IIRC, but those are rarely emitted.

Re: PowerShell is open sourced and is available on Linux

#788
post #667

Earlier quoted context omitted.

And just think how much faster it would be if there were no serialization and I/O involved at all...

And my method can work over distributed systems with network streams... There are advantages to streams of text.

What advantages?

PowerShell works over networks just fine, because standardized ISO/IEC 17963:2013 protocol a.k.a. WS-Management.

Re: PowerShell is open sourced and is available on Linux

#789
post #506

Earlier quoted context omitted.

After a number of years using PowerShell, my conclusion is the opposite: text "scraping" is just better for most cases. Normal shell usage means doing a lot of one-shot pipelines incrementally. This is just easier and faster to do when passing text around because you can look at it and not have to inspect some object for it's type and what attributes/methods it provides. Parsing the text is not the problem here (alth…

> text "scraping" is just better for most cases. Unix pipes handle bytes, not just text. For instance, copy a hard disk partition to a remote hard disk via ssh: (dd if=/dev/hda1) | (ssh root@host dd of=/dev/sda1) The KISS principle ("Keep it simple, Stupid") is the best way in many cases. In Unix you can quickly enter a pipe without special coding which does also non-trivial stuff. For instance, find -name "*.xls" -e…

A better way to do that find command is:

    find -name '*.xls' -print0 | xargs -0 xls2csv

Re: PowerShell is open sourced and is available on Linux

#790

Earlier quoted context omitted.

> Can you do this in Powershell quickly? I don't know, I am actually curious. You can basically do the same thing with Powershell. I don't know of a 'built-in' module to handle XLS->CSV conversion, so you need to bring one in: Install-Module ImportExcel Then: ls *.xlsx -r | %{ Import-excel $_ } | ? { $_.Name -eq "Miller" } | sort That's my naive, Powershell noob approach anyway. There's another option however, where…

Thanks for pointing this out. However, your example is not equivalent since "ls" searches only in the current directory. Nevertheless it is good to know that it's basically possible since it helps a lot to manage mixed Windows/Linux networks.

Not true. The -r flag I specified is for "recurse", will search current and all sub-directories.
Post reply on HN