Picking up on the comment of @user31264, CPI is calculated with a formula like this:
\begin{align}
CPI_t = \frac{\sum_i w_i p_{it}}{\sum_i w_i p_{it^*}}
\end{align}
Price of item $i$ at time $t$ is $p_{it}$. Prices in the baseline year are $p_{it^*}$. Each price's weight in the CPI is $w_i$. These weights are determined from a "market basket" which represents an attempt to match the spending habits of a typical US, urban household (assuming you are talking about the CPI-U for the US) --- you can productively think of these weights as representing the quantity of item $i$ bought by an average US household. The weights are not literally these quantities, but it is OK to think about them this way most of the time.
Some of the items (some of the $i$) are food items, and some are not. Let's denote the food items as $i \in F$ and the non-food items as $i \not\in F$. Then CPI-food and CPI ex food look like:
\begin{align}
CPI_t^F &= \frac{\sum_{i \in F} w_i p_{it}}{\sum_{i \in F} w_i p_{it^*}}\\
&\strut \\
CPI_t^{\tilde{}F} &= \frac{\sum_{i \not\in F} w_i p_{it}}{\sum_{i \not\in F} w_i p_{it^*}}\\
\end{align}
Now, we can do some algebra:
\begin{align}
CPI_t &= \frac{\sum_i w_i p_{it}}{\sum_i w_i p_{it^*}}\\ \strut \\
&= \frac{\sum_{i \in F} w_i p_{it}+\sum_{i \not\in F} w_i p_{it}}
{\sum_iw_ip_{it^*}} \\ \strut\\
&= \frac{\sum_{i \in F} w_i p_{it^*}}{\sum_iw_ip_{it^*}}
\frac{\sum_{i \in F} w_i p_{it}}{\sum_{i \in F} w_i p_{it^*}}
+\frac{\sum_{i \not\in F} w_i p_{it^*}}{\sum_iw_ip_{it^*}}
\frac{\sum_{i \not\in F} w_i p_{it}}{\sum_{i \not\in F} w_i p_{it^*}}
\\ \strut\\
&=\frac{\sum_{i \in F} w_i p_{it^*}}{\sum_iw_ip_{it^*}} \cdot CPI_t^F
+\frac{\sum_{i \not\in F}w_i p_{it^*}}{\sum_iw_ip_{it^*}}\cdot CPI_t^{\tilde{}F}
\\ \strut \\
CPI_t^{\tilde{}F} &= \frac{\sum_iw_ip_{it^*}}{\sum_{i \not\in F}w_i p_{it^*}}
\cdot CPI_t
-\frac{\sum_{i \in F} w_i p_{it^*}}{\sum_{i \not\in F}w_i p_{it^*}}
\cdot CPI_t^F
\end{align}
So, to back out CPI ex food from CPI and CPI food, you divide overall CPI by the proportion of spending on non-food in the baseline year (the year the market basket was measured in), then you subtract off the CPI food times the ratio of food to non-food spending in the baseline/market-basket year.
You need to be careful that each of the years of CPI data you use are calculated based on the same market basket. The Bureau of Labor Statistics does occasionally update the market basket. Currently, CPI is based on a 2009/10 market basket. Furthermore, if you use a "chained" index, the market basket is updated every year, so that the method outlined here does not apply.
Finally, a caveat. What the BLS actually does to calculate the CPI is more complicated than what I have laid out above. What I have laid out above is the basic idea, but the implementation details are dizzying. Spend a long time reading the various reports and documentation on the BLS website if you want to actually understand.