xargs with multiple arguments

后端 未结 12 1774
独厮守ぢ
独厮守ぢ 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-13 08:44

    Here is a solution using sed for three arguments, but is limited in that it applies the same transform to each argument:

    cat input.txt | sed 's/^/--file=/g' | xargs -n3 my-program
    

    Here's a method that will work for two args, but allows more flexibility:

    cat input.txt | xargs -n 2 | xargs -I{} sh -c 'V="{}"; my-program -file=${V% *} -file=${V#* }'
    

提交回复
热议问题