Skip to main content
added 77 characters in body
Source Link
luator
  • 312
  • 2
  • 10

I have a CSV file and want to run a command for each line, using the fields of the file as separate arguments.

For example given the following file:

foo,42,red
bar,13,blue
baz,27,green

I want to run the following commands one after another (note that order of arguments in the command may differ from the input file):

my_cmd --arg1 42 --arg2 foo --arg3 red
my_cmd --arg1 13 --arg2 bar --arg3 blue
my_cmd --arg1 27 --arg2 baz --arg3 green

What is the easiest way to achieve this? It seems like it might be possible with xargs but I couldn't figure out how exactly.

I have a CSV file and want to run a command for each line, using the fields of the file as separate arguments.

For example given the following file:

foo,42,red
bar,13,blue
baz,27,green

I want to run the following commands one after another:

my_cmd --arg1 42 --arg2 foo --arg3 red
my_cmd --arg1 13 --arg2 bar --arg3 blue
my_cmd --arg1 27 --arg2 baz --arg3 green

What is the easiest way to achieve this? It seems like it might be possible with xargs but I couldn't figure out how exactly.

I have a CSV file and want to run a command for each line, using the fields of the file as separate arguments.

For example given the following file:

foo,42,red
bar,13,blue
baz,27,green

I want to run the following commands one after another (note that order of arguments in the command may differ from the input file):

my_cmd --arg1 42 --arg2 foo --arg3 red
my_cmd --arg1 13 --arg2 bar --arg3 blue
my_cmd --arg1 27 --arg2 baz --arg3 green

What is the easiest way to achieve this? It seems like it might be possible with xargs but I couldn't figure out how exactly.

Became Hot Network Question
Source Link
luator
  • 312
  • 2
  • 10

Run command on each line of CSV file, using fields in different places of the command

I have a CSV file and want to run a command for each line, using the fields of the file as separate arguments.

For example given the following file:

foo,42,red
bar,13,blue
baz,27,green

I want to run the following commands one after another:

my_cmd --arg1 42 --arg2 foo --arg3 red
my_cmd --arg1 13 --arg2 bar --arg3 blue
my_cmd --arg1 27 --arg2 baz --arg3 green

What is the easiest way to achieve this? It seems like it might be possible with xargs but I couldn't figure out how exactly.