2

I have a simple text file (command_script.txt) that I am executing as a bash script.

The content of command_script.txt is something like this:

#!/bin/bash
some_command -flags input1 output1
some_command -flags input2 output2
some_command -flags input3 output3
...
some_command -flags input1000 output1000

I execute it on the command line (./command_script.txt) and it runs through one line at a time. Is there an easy way I can run 20 lines at a time in parallel?

Thanks!

2 Answers2

1

By appending "&" at the end of a line a process is launched in background. Hence, the next one is started immediately such that both are running in parallel.

miro
  • 67
  • 6
1
#!/usr/bin/parallel --shebang -j20
some_command -flags input1 output1
some_command -flags input2 output2
some_command -flags input3 output3
...
some_command -flags input1000 output1000

If the commands are literaly the ones given, you can instead do:

seq 1000 | parallel -j20 some_command -flags input{} output{}
Ole Tange
  • 31,768
  • 5
  • 86
  • 104