xargs with multiple arguments

后端 未结 12 1733
独厮守ぢ
独厮守ぢ 2020-12-13 08:05

I have a source input, input.txt

a.txt
b.txt
c.txt

I want to feed these input into a program as the following:

<         


        
12条回答
  •  北海茫月
    2020-12-13 08:46

    Actually, it's relatively easy:

    ... | sed 's/^/--prefix=/g' | xargs echo | xargs -I PARAMS your_cmd PARAMS

    The sed 's/^/--prefix=/g' is optional, in case you need to prefix each param with some --prefix=.

    The xargs echo turns the list of param lines (one param in each line) into a list of params in a single line and the xargs -I PARAMS your_cmd PARAMS allows you to run a command, placing the params where ever you want.

    So cat input.txt | sed 's/^/--file=/g' | xargs echo | xargs -I PARAMS my-program PARAMS does what you need (assuming all lines within input.txt are simple and qualify as a single param value each).

提交回复
热议问题