-1

I have a shell script that takes three arguments, which need to come from a single line of a text file.

Example text file:

1   1   2300000
1   2300001 5300000
1   5300001 7100000
1   7100001 9200000
1   9200001 12600000

I want to run the script once for each line:

sbatch script 1 1   2300000
sbatch script 1 2300001 5300000

... And so on

I'm trying to write code to include these three arguments for every line of the text file. So far, I've tried a few things, including:

while read x y z in text
do
    ./script $x $y $z
done

I've found similar questions on here but they don't quite answer my problem. I'm about ready to just submit each line manually, so any help or suggestions on how to do this would be greatly appreciated!

  • What do you want to do that isn’t done by the code you have? – G-Man Mar 13 '18 at 1:30
  • Alternative: xargs -L 1 sbatch script <file – Toby Speight Mar 13 '18 at 9:00
2
while read x y z; do
    ./script "$x" "$y" "$z"
done < FILENAME

note FILENAME and not using in text

Check bash FAQ #1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.