A powershell question: I want to extract each line in a character stream produced by an application that matches a certain pattern which in pseudo-code would be something like this:
PS> <a_ps_command> <the_application_command_for_outputting_the_text_stream> | <my_filter > output_file.txt
In my case the application is a CM-tool that outputs the change history of a source file and the (psuedo)pattern should be something like:
<a couple of numbers><a name><a time stamp><a line of characters>
Cheers,
Christian
The filtering cmdlet in PowerShell is
Where-Object(aliasesWhereand?). You simply pass the output of the SCM command into it. You then use $_ to represent the current line and test against it e.g.:The
-Matchoperator is used to compare the current line of output against a regex. I use^\d+to filter out the first two lines oftf histoutput (which are formatting strings) and then I search on the textHackanywhere else on the line (looking for it in comments for instance). You would modify and enhance the regex to meet your needs.