My google-fu fails me again. The information is (probably) there, but I cannot find it. I know that UNIX, like the back of my hand, uses cygwin, etc. However, with the increasing availability of Powershell on servers and (at least on production servers) the difficulties of getting cygwin in place, I am trying to pick up Powershell. If nothing else, this is another weapon in my arsenal.
Essentially, I'm looking for the Powershell equivalent of the awk command:
awk '$9 == "503" { print $0 }' < access_log
For those who don't know awk, this basically compares field 9 of the input file and then executes the block (this is the apache access log, so it returns me all the lines from access_log where the HTTP status code 503 is returned). Awk handles space-based file splitting automatically; $ 0 - the entire line (unmodulated), with separate fields going to $ 1, $ 2, ... [etc].
I know that I can use split as follows:
cat access_log | %{ $_.split() }
which splits the incoming lines into an array, but I can’t work out here how to use select-objector where-objectto select (and output) whole lines based on a given field.
An alternative is select-string, but I see no way to pass an expression in strings %{ $_.split()[8] -eq "503" }. (I note that powershell is null, so it looks in field 8).
, - , google-fu, ( , - ).
: -)