You can devide dialing plans but you have to be careful with some features like callparking.
If you have two companies and one asterisk server with a proper number plan it is not that hard to get them separated. If all the numbers of company 1 starts with 5 and the numbers of company 2 starts with 6 and the numbers have 4 positions a very basic dialplan could lok something like this.
In the sip entries for internal phones for company 1 you add context=company_1 and for company 2 you add context=company_2
This in’t the whole story but if yo understand the above I think you are halfway. Search for numbermatching and do a lot of reading and trying. Success!
If this is all that is in extensions.conf and in the sip entries of company 1 in sip.conf you add context=company_1 and the sip entries for company 2 you add context=company_2 you should have seprated dialplans that can’t touch each other. Don’t forget to reload.
For a good understanding you also have to read about how to include contexts or a .conf file into a context and by including make it part of that context .
I didn’t copied it from a working system so perhaps there is a typo (or two)