Real Analysis, Folland Theorem 1.18 Borel measures on the real line Background information - We fix a complete Lebesgue-Stiltjes measure $\mu$ on $\mathbb{R}$ associated to the increasing right continuous function $F$, and we denote by $M_{\mu}$, the domain of $\mu$.
1.17 Lemma - For any $E\in M_{\mu}$, $$\mu(E) = \inf\{\sum_{1}^{\infty}\mu((a_j,b_j)):E\subset \bigcup_{1}^{\infty}(a_j,b_j)$$

Theorem 1.18 - If $E\in M_{\mu}$, then \begin{align*}
\mu(E) &= \inf\{\mu(U):E\subset U, U \ \text{open}\}\\
&=\sup\{\mu(K):E\subset K, K \ \text{compact}\}\end{align*}

Proof - By lemma 1.17, for any $\epsilon > 0$ there exists intervals $(a_j,b_j)$ such that $E\subset \bigcup_{1}^{\infty}(a_j,b_j)$ and $\sum_{1}^{\infty}\mu((a_j,b_j))\leq \mu(E) + \epsilon$. If $U = \bigcup_{1}^{\infty}(a_j,b_j)$ then $U$ is open, $E\subset U$, and $\mu(U)\leq \sum_{1}^{\infty}\mu((a_j,b_j))\leq \mu(E) + \epsilon$. Since $E\subset U$ then $\mu(E)\leq \mu(U)$ so the first part is done.
I am not sure how to prove the second part, specifically following follands proof I am confused how when we choose $\overline{E}\setminus E\subset U$ such that $\mu(U)\leq \mu(\overline{E}\setminus E) + \epsilon$. Then if we let $K = \overline{E}\setminus U$ this somehow makes $K$ compact?
 A: Proof of part 1 is fine. I have just copied it to add few more details. The proof of part 2 I have also written it in detail.

If $E\in M_{\mu}$, then \begin{align*}
\mu(E) &= \inf\{\mu(U):E\subset U, U \ \text{open}\}\\
&=\sup\{\mu(K):E\subset K, K \ \text{compact}\}\end{align*}

Proof -
(Part 1) Let us prove $\mu(E) = \inf\{\mu(U):E\subset U, U \ \text{open}\}$.
By lemma 1.17, for any $\epsilon > 0$ there exists intervals $(a_j,b_j)$ such that $E\subset \bigcup_{1}^{\infty}(a_j,b_j)$ and $\sum_{1}^{\infty}(a_j,b_j)\leq \mu(E) + \epsilon$. If $U = \bigcup_{1}^{\infty}(a_j,b_j)$ then $U$ is open, $E\subset U$, and $\mu(U)\leq \sum_{1}^{\infty}(a_j,b_j)\leq \mu(E) + \epsilon$. Since $E\subset U$ then $\mu(E)\leq \mu(U)$,
we have that
$$\mu(E)\leq \mu(U) \leq \mu(E) + \epsilon$$
So, we have  proved that, for any $\epsilon > 0$, there $U$ such that $U\supset E$, $U$ is open and
$$\mu(E)\leq \mu(U) \leq \mu(E) + \epsilon$$
so the first part is done.
(Part 2) Let us prove $\mu(E) =\sup\{\mu(K):K\subset E, K \ \text{compact}\}$.
First suppose $E$ is bounded. Then there is $n\in \mathbb{N}$ such that $E\subset [-n,n]$. Then, $[-n,n]\setminus E \in  M_{\mu}$ and then,  by part 1,
$$\mu([-n,n]\setminus E) = \inf\{\mu(U):([-n,n]\setminus E)\subset U, U \ \text{open}\}$$
So , for any $\varepsilon>0$, there is $U$ such that $([-n,n]\setminus E)\subset U$, $U$ is open and
$$\mu([-n,n]\setminus E)\leq \mu(U) \leq \mu([-n,n]\setminus E) + \epsilon$$
So we have,  for any $\varepsilon>0$, there is $U$ such that $([-n,n]\setminus U)\subset E$, $U$ is open and
$$\mu(E)=\mu([-n,n])-\mu([-n,n]\setminus E)\geq \mu([-n,n])-\mu(U) \geq \\ \geq \mu([-n,n])-\mu([-n,n]\setminus E) -\varepsilon=\mu(E)-\varepsilon$$
Note that $([-n,n]\setminus U)$ is closed and bounded, so it is compact and $\mu([-n,n]\setminus U)=\mu([-n,n])-\mu(U)$.
So we proved that for any $\varepsilon>0$, there is $K$ (take $K=[-n,n]\setminus U$) such that $K\subset E$, $K$ is compact and
$$\mu(E)\geq \mu(K) \geq \mu(E)-\varepsilon$$
So we have proved that, if $E\in M_{\mu}$ is bounded then
$$\mu(E) =\sup\{\mu(K):K\subset E, K \ \text{compact}\}$$
If $E$ is not bounded, then define, for $j\in \mathbb{Z}$, $Ej=E\cap (j,j+1]$. Note that for each $j$, $E_j\in M_{\mu}$, $E_j$ is bounded. Moreover, $\{E_j\}_{j \in \mathbb{Z}}$ is a family of disjoint sets. Now, given any $\varepsilon>0$, since each $E_j$ is in $M_{\mu}$ and is   bounded, there is $K_j$ compact, such that $K_j\subset E_j$   and
$$\mu(E_j)\geq \mu(K_j) \geq \mu(E_j)-\frac{\varepsilon}{2^{|j|+2}}$$
Let $H_n=\bigcup_{-n}^{n-1} K_j$. We have that $H_n$ is compact and $H_n \subset E$. We also have
\begin{align*}\mu(E) \geq \mu(H_n)=\sum_{j=-n}^{n-1}\mu(K_j) & \geq \sum_{j=-n}^{n-1}\mu(E_j)-\sum_{j=-n}^{n-1}\frac{\varepsilon}{2^{|j|+2}}= \\
& =\mu(E\cap (-n,n])-\sum_{j=-n}^{n-1}\frac{\varepsilon}{2^{|j|+2}}\geq \\
& \geq  \mu(E\cap (-n,n])-\frac{3}{4}\varepsilon \end{align*}
Since $(E\cap (-n,n])_{n\in\mathbb{N}}$ is a non decreasing sequece of sets and $E=\bigcup_n (E\cap (-n,n])$ we have that $\lim_{n\to\infty}\mu(E\cap (-n,n])=\mu(E)$. So take $n_0$ such that
$$\mu(E\cap (-n_0,n_0])\geq\mu(E)-\frac{\varepsilon}{4}$$
So we get
\begin{align*}\mu(E) \geq \mu(H_n)\geq \mu(E\cap (-n,n])-\frac{3}{4}\varepsilon \geq\mu(E)-\varepsilon\end{align*}
So we have proved that, if $E\in M_{\mu}$ (bounded or not) then
$$\mu(E) =\sup\{\mu(K):K\subset E, K \ \text{compact}\}$$
Remark: An alternative proof for the case where  $E$ is not bounded in (Part 2) is as follows:
If $E$ is not bounded, since for all $K\subset E$, $\mu(K)\leq \mu(E)$, we
$$\sup\{\mu(K):K\subset E, K \ \text{compact}\} \leq \mu(E)$$
Define, for $j\in \mathbb{N}$,$j>1$ $E_j=E\cap [-j,j]$. Note that $\{E_j\}_j$ is a monotone non-decreasing sequence of measurable sets and
$$E=\bigcup_jE_j$$
So, since $\mu$ is continuous from below, we have $\lim_{j\to \infty}\mu(E_j)=\mu(E)$.
Now, given any $\varepsilon>0$, since each $E_j$ is in $\mathcal{L}^n$ and is bounded, there is $K_j$ compact, such that $K_j\subset E_j$   and
$$\mu(E_j)-\frac{\varepsilon}{j}\leq \mu(K_j) \leq \mu(E_j)$$
So we have $\lim_{j\to \infty}\mu(K_j)=\mu(E)$.
So we have
$$\mu(E) =\sup\{\mu(K):K\subset E, K \ \text{compact}\}$$
A: In the part of the proof you're referring to, $E$ is assumed to be bounded. Therefore $K=\overline{E}\setminus U$ is also bounded, and since $K=\overline{E}\cap U^c$ is closed it follows that $K$ is compact.
