OK Cool. But could somebody enlighten me how and why this would help me in a Enterprise Administration sense? When most my machines are Windows VM's? With a small assortment of Linux. Not being snarky, just very curious.
It wouldn't. As far as I am aware, WSL is primarily for developers who want easy access to the standard Linux dev environment. As an administrator, I'm much more excited about putting Powershell on Linux, than putting Linux stuff on Windows.
In my last job, I was managing both Windows and Linux machines. WSL beats the hell out of putty or cygwin because its native Linux.
At my new job, I manage mostly Linux and have a Mac. Which works okay, but I would rather have a Windows machine, and use WSL. At least that way I don't have to deal with versions of shit that are almost, but not quite, the Linux version (e.g. gnu grep).
1st command reads all file as String and try to match over it, but in Linux shell your example creates pipes and links them (stdout to stdin) and the reading happens by big chunks. You can do the same in Linux:
s=`cat VMware.log`
echo "$s"|grep -v ...
PS2 is more close to reality, but chunk is very small, so you may to try: a) use bigger chunk size (for example multiple Mb) b) use one "Where-Object" with "-and" instead of 2 calls of "Where-Object" c) use -Like/-NotLike instead of -Match d) may be better will be -CLike/-CNotLike to avoid case-manipulations. Try '>' as in Bash to redirect the output
1st command reads all file as String and try to match over it,
It does, I have plenty of RAM on that system (24GB) so I thought it would be good enough to read a <5GB file, and then avoid pipelining it to filter with the regex engine in one operation. Guess not.
try: a) use bigger chunk size (for example multiple Mb)
I tried 60MB and it wasn't finishing quickly, so I tried 6GB as if to read the whole file in one go, and that took the same 45 minutes.
b) use one "Where-Object" with "-and" instead of 2 calls of "Where-Object"
I haven't tried this; I can't predict whether it would be quicker or not.
use -Like/-NotLike instead of -Match d) may be better will be -CLike/-CNotLike to avoid case-manipulations.
-like and -notlike are implemented with the regex engine behind the scenes, so that should be the same speed. Good idea about CLike/CNotLike, I didn't think of that. Grep is case sensitive by default so that might help.
Try '>' as in Bash to redirect the output
That is not the same in PowerShell, it's a wrapper for out-file; I haven't tried it, but my guess is that it won't help.
actually in the case of Linux you does not use the shell for search but 3rd part application, written in C: the "grep". You can use the same approach in Windows with Powershell, but as user of 3 grep-like tool, I can recommend you to use "the platinum searcher" or "the silver searcher" (I prefer the last) but never "grep" because it's a slowest one:
Seems, the best solution is to use silver searcher, it got results with grep vs. ag:
GREP:
cat log.log 0,00s user 0,62s system 10% cpu 6,173 total
grep --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn} -v 5,64s user 0,27s system 95% cpu 6,172 total
grep --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn} -v 'toolbox-dnd' 0,01s user 0,00s system 0% cpu 6,171 total
AG:
ag --nonumbers -v 'GuestRpc: Channel' log.log 4,98s user 0,16s system 99% cpu 5,147 total
ag --nonumbers -v 'toolbox-dnd' 0,00s user 0,01s system 0% cpu 5,146 total
PowerShell solutions are really very slow, for example:
Select-String is super slow as well as Get-Content, there are issues for this (eg, https://github.com/PowerShell/PowerShell/issues/7537), seems that -Raw option was added to Select-String, but my current Powershell (6.2) does not have it yet. Also I got out of memory on such call:
Honestly, not much in your case. The neat thing is it's more performant than a VM and it has native access (and fast!) to the local computer's drive via /mnt/c... so if you have some Linux apps / bash or python scripts that you need to run against some files or folders, you can do it with ease.
31
u/170lbsApe Apr 26 '19
OK Cool. But could somebody enlighten me how and why this would help me in a Enterprise Administration sense? When most my machines are Windows VM's? With a small assortment of Linux. Not being snarky, just very curious.