Re:Foreign Linux: Run Linux binaries on Windows without driv...
by hug on Thursday March 12, 2015 @09:26AM
(#9190592)
For 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
Re:Foreign Linux: Run Linux binaries on Windows without driv...
by ygra on Thursday March 12, 2015 @12:35PM
(#9191888)
You 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.
Re:Foreign Linux: Run Linux binaries on Windows without driv...
by bgilroy26 on Thursday March 12, 2015 @04:39PM
(#9193728)
Today, I learned "Heath Robinson" is British English for "Rube Goldberg"
Re:Foreign Linux: Run Linux binaries on Windows without driv...
by Raesan on Thursday March 12, 2015 @08:35AM
(#9190332)
You 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
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.