Skip to content

How to adjust the argument position in xargs?

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

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  1. How to resolve the ‘/bin/rm: Argument list too long’ error
  2. xargs when the filename contains a newline
  3. Run tasks in parallel with xargs
  4. Quickly open to file and position a cursor with vim
  5. How to check which directory used up most of the disk space?

2 Comments

  1. Ole Tange wrote:

    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

    Friday, June 25, 2010 at 5:36 pm | Permalink
  2. Linux Ask! wrote:

    Hello,

    Thanks for you tips.

    Unfortunately, parallel is not included in most common distributions like Ubuntu.

    Saturday, June 26, 2010 at 4:10 am | Permalink

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*