3

Is there a way to run multiple commands at the same time, but not moving on until both are finished? I have been trying to use similar instructions to the following, but both take a long time to complete and would be better if I could run them at the same time (cannot use & to run it on the background since the next step requires all the output files)

sed -i 's/x/y/' file1
grep 'pattern' file2 > file3 
BioFalcon
  • 51
  • 5
  • `( command )`. this launches a subshell. it's multi-processing. then you can call `wait` on both pid. have a look at a complete doc: http://tldp.org/LDP/abs/html/index.html. – Jason Hu Jun 09 '15 at 14:54
  • 2
    You can use & and wait – 123 Jun 09 '15 at 15:08

2 Answers2

3

This is probably what you want:

sed -i 's/x/y/' file1 &
grep 'pattern' file2 > file3 &
wait
twalberg
  • 59,951
  • 11
  • 89
  • 84
1

Not exactly the answer, but a few lines of makefile would do what you want

file1:
    sed -i 's/x/y' <someinput

file3: file2
    grep 'pattern' file2 > file3

nextop: file1 file3
    whatever you want to do next

and make -j so that tasks are done in parallel when possible

Andrew McGuinness
  • 2,092
  • 13
  • 18