3 ms·
To be honest, and I say this with a massive cringe, after 20 years of Unix I'm more productive with PS in a couple of months! It's quite refreshingly easy to us
by cssmoo 12y ago
To be honest, and I say this with a massive cringe, after 20 years of Unix I'm more productive with PS in a couple of months! It's quite refreshingly easy to use and I genuinely had no idea how much time I was wasting on parsing streams.
Now I feel horrible for revealing my dirty secret :(
- joelthelion 12y agoWhat do you use for grep? I tried using Powershell and did a few things with it, but while it is a great shell, the lack of good tools like grep prevented me from being really productive.
- cron 12y ago`select-string` or it's alias `sst`. I find myself filtering collections of objects far more frequently then grepping lines when using powershell.
- nailer 12y agoI use `where` for finding stuff, but that's based on structure rather than scraping.
- pjc50 12y agoI've ended up with Select-String "pattern" -Path file.txt | ForEach-Object { Write-Output $_.Line } | Out-File t.txt Slightly Heath Robinson, but by default PS will truncate lines to terminal width, even when writing to a file, which is a disaster for any kind of subsequent machine processing.
- Raesan 12y agoYou could also use either of these: (Select-String "pattern" -Path file.txt).Line > t.txt Select-String "Pattern" -Path file.txt | Select-Object -ExpandProperty Line > t.txt Or equivalent to the second example but with shortcuts: sls pattern -path file.txt | select -exp line > t.txt
- hug 12y agoFor the uninitiated this looks completely barbaric, but makes a whole lot of sense when you consider that PS is built around an object-based pipeline. 'Select-String' in PS doesn't actually return a string, but a 'MatchInfo' object, which contains more properties -- 'linenumber', 'context', etc, as well as the 'line' property which contains the actual matched lines as strings. The default output from any part of the pipeline is a human-readable/terminal-display-compatible representation of the object's commonly used properties, thus the truncation. As an aside, you can replace the foreach with select-object for an efficiency gain: sls "Pattern" file.txt | select -exp line | out-file t.txt
- ygra 12y agoYou also don't technically need to go through Select-String if all you care about is the line itself: (gc file.txt) -match "Pattern" | Out-File t.txt Comparison operators that get an array as their left argument return the items where the comparison returns true.
- bgilroy26 12y agoToday, I learned "Heath Robinson" is British English for "Rube Goldberg" http://en.wikipedia.org/wiki/W._Heath_Robinson http://en.wikipedia.org/wiki/W._Heath_Robinson
- rudolf0 12y agoDefault Windows shell also has `findstr`, which works very similarly to grep. It's also quite fast.
- emodendroket 12y agoYeah, I think the object pipeline is very nice.
- swah 12y agoButs its not just the shell, its ps, kill, convert, ffmpeg... do you feel like you can do most stuff you do on linux in PS?
- jdboyd 12y agoInstalling ffmpeg and convert on Windows (without cygwin even) is trivial. It looks like PowerShell even has kill (as an alias to Stop-Process) and ps (as an alias to Get-Process). I don't like PowerShell, but I certainly wouldn't be quick to suggest that it is missing features.
- phaemon 12y agoYou're a .Net developer who wrote a C# framework back in 2004 and consistently posts about how great Windows is and how poor Linux is. At a wild guess I'd say that's why you're "more productive with PS in a couple of months".