tomka
tomka

Reputation: 385

Using a substring in a PowerShell pipeline

Is there a possibility to manipulate the items in a pipeline of PowerShell?

In more concrete words: I start my pipeline with an "svn list". This returns me a list of paths in my repository, all directories with a trailing "/". The list of paths should be stored in an array, but without the "/".

This:

svn list svn://server/repository/myPath | $_.TrimEnd("/")

does not work because TrimEnd is an expression and may not be used within a pipeline.

The result of the pipeline should be something like:

$a = @("foo", "bar)

Upvotes: 3

Views: 14983

Answers (2)

ravikanth
ravikanth

Reputation: 25810

I don’t have the SVN stuff to try the same here. But, from what I see, you are missing a ForEach-Object (aliases % and foreach) after the pipe.

Try this

svn list svn://server/repository/myPath | ForEach-Object { $_.TrimEnd("/") }

or

svn list svn://server/repository/myPath | % { $_.TrimEnd("/") }

Upvotes: 17

Zombo
Zombo

Reputation: 1

Use:

svn list svn://server/repository/myPath | % TrimEnd /

Upvotes: 2

Related Questions