2

Linux GNU xargs

I have the file doit with

arg1 arg2 arg3 arg4
arg1 arg2 arg3 arg4

I want to perform

command arg1 arg2 arg3 arg4
command arg2 arg2 arg3 arg4

What I can't figure out is how to do this with xargs

If one does xargs -a doit -I % command %

It runs

command 'arg1 arg2 arg3 arg4'

i.e run command with the first argument = 'arg1 arg2 ....'

2
  • I think you are using the wrong tool. xargs is meant to gather an unknown amount of arguments from STDIN or a file, and run a command an unknown amount of times. You know exactly how many arguments you have and how many times to run your command. Feb 25, 2014 at 17:39
  • @KevinPanko not quite correct. I ran into this use-case, where I know I have N number of lines, each containing 2 args. So I want to be able to expand string into multiple args (by space, using regular bash semantics) before passing it into cmd. xargs doesn't seem to do that
    – ffledgling
    Jun 5, 2019 at 19:26

1 Answer 1

0

If you use GNU Parallel you can do:

parallel -a doit eval command

or:

parallel -a doit --colsep ' ' command

To learn more: Watch the intro video for a quick introduction: https://www.youtube.com/playlist?list=PL284C9FF2488BC6D1 and walk through the tutorial (man parallel_tutorial). You command line with love you for it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .