I have a txt file with 100 lines and 5 columns. I want to automatize a script, with reading the file each lines, make the first column the first argument, the second column the second argument etc. How can solve this?
1 Answer
It's hard to be definitive without a real example from you, but you can use the array form of the bash shell's built-in read function something like:
while read -ra arr; do cmd "${arr[@]}"; done < fileEx. given a file
$ cat file
foo some arg 3
bar otherarg 5 -o bar
baz "arg with spaces" -99then
$ while read -ra arr; do echo cmd "${arr[@]}"; done < file
cmd foo some arg 3
cmd bar otherarg 5 -o bar
cmd baz "arg with spaces" -99Alternatively, if your command arguments are simple (no quoted spaces for example) then you could try xargs e.g.
xargs -L1 -a file cmd