0

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!

2

1 Answer 1

3
while read x y z; do
    ./script "$x" "$y" "$z"
done < FILENAME

note FILENAME and not using in text

Check bash FAQ #1

2
  • ,I tried this approach, just replaced ./script and FILENAME with fully qualified paths/filename but it's not working. Even though there is no error. My program only takes 1st line from a source file with multiple arguments on a single line. But I have multiple lines. And then the script n reality does not do what it should, however the console output looks right. Nov 2, 2023 at 23:44
  • I instead tried this: for arg in $(< /Users/Git-Repos/File-With-Multiple-Arguments-Per-Line.txt); do python /Users/Git-Repos/MyProgram.py "$arg" "$arg" ; done. Usage is such python MyProgram.py input-file.txt output-file.txt I does what need though it for some reason processes each argument 2 times (so. 1st arg is input-file is treated both as output-file; same with 2nd arg). So i end up modifying the input file, which I should not. Nov 2, 2023 at 23:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .