Strip leading and trailing whitespace when piping to GNU parallel

When I try to write a pipeline like this:

git branch | rg '^*' | parallel git pull {}

I run into a problem with whitespace. Because the branch names have leading whitespace, parallel ends up attempting to run git pull ' foo' which is wrong.

Is there an argument for GNU Parallel that says "strip trailing/leading whitespace"? Alternatively, is there a separate program that does this?

I am aware that I could:

  • Use cut -c 3- but this only works if leading space is consistent
  • Use sed or awk, but these result in having to type a complex expression every time
Asked By: Dommondke

||

--trim rl

git branch | rg -v '^*' | parallel --dr --trim rl git pull {}
Answered By: Ole Tange
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.