Re: grep, which, and tail commands?



Jon,

For grep equivalence take a look at get-content with a where-object in
the second pipeline step.

For example, you want to find lines in a file that match a regular
expression pattern:

get-content filename |
where-object {$_ -match "regularExpressionPattern"}

Adapt as necessary.

For tail take a look at the -first and -last parameters on
select-object. You would typically use it with a sort-object in the
preceding pipeline step to order objects according to the criterion of
interest.

I am not too familiar with "which" but from your description something
like

get-childitem Script1.ps1 |
format-list Name, PSParentPath

should give you something similar to what you want.

Andrew Watt MVP
Author - Professional Windows PowerShell (Wrox)

On Mon, 3 Jul 2006 14:37:01 -0700, Jon Miller <Jon
Miller@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

Hi,

I'm just starting to play around with PowerShell. It seems pretty cool.
There are a few things that I'm wondering though. Namely, I'm wondering if
there are equivalents for UNIX commands grep, which, and tail. With regard to
grep, I'm wondering if there are plans for an updated version of FINDSTR.EXE
that is possibly more robust. I've also found the UNIX which command very
valuable. It tells you where in your path an executable file is found. And
also, tail with the -f flag is very valuable for viewing log files and having
their output displayed as new output is written to them. I've created my own
.NET implementations (in C#) of the later two commands, but, I was thinking
it would be nice since there seems to be interest in finally getting a decent
shell going for Windows that these other commands be bundled with the OS
and/or the shell.

Jon
.



Relevant Pages