How to adjust the argument position in xargs?
Answer:
Sometimes you might want to adjust the argument position when using the xargs command, e.g.
echo "foo" | xargs echo "bar"
It gives:
bar foo
Instead, you want the piped argument "foo" to be inserted before the "bar", you can use
echo "foo" | xargs -i echo {} "bar"
Now it gives:
foo bar
That's very handy


2 Comments
With GNU Parallel http://www.gnu.org/software/parallel/ you do not need the -i:
echo "foo" | parallel echo {} "bar"
and you get the added advantage the jobs will be run in parallel.
Watch the intro video to GNU Parallel: http://www.youtube.com/watch?v=OpaiGYxkSuQ
Hello,
Thanks for you tips.
Unfortunately, parallel is not included in most common distributions like Ubuntu.
Post a Comment