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 
2
  • ( command ). this launches a subshell. it's multi-processing. then you can call wait on both pid. have a look at a complete doc: tldp.org/LDP/abs/html/index.html. Commented Jun 9, 2015 at 14:54
  • 2
    You can use & and wait Commented Jun 9, 2015 at 15:08

2 Answers 2

3

This is probably what you want:

sed -i 's/x/y/' file1 &
grep 'pattern' file2 > file3 &
wait
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.