I am trying to prove Lusin's theorem on the real line, I'll write the statement and my attempt at a proof:
Statement
Let $f: \mathbb R \to \mathbb R$ be a measurable function. For every $\epsilon>0$, there is a continuous function $g: \mathbb R \to \mathbb R$ such that $m(\{f \neq g\})<\epsilon$.
Attempt at a solution
I've already proved this statement for $f:E \to \mathbb R$ with $E$ of finite measure. My idea was to partition $\mathbb R$ in disjoint intervals of the form $[k,k+1)$ for $k$ integer, then, on each of these intervals extract a closed set $F_k$ such that $f$ is continuous on this set and such that when I take the countable union of the complement of each $F_k$, the measure of this union is less than $\epsilon$. Then I could linearly extend $f$ to the union such that the extension $g$ is continuous on the real line.
So, suppose the statement is true for sets of finite measure. For each $k$ integer, there exists $F_k$ closed set such that $m({F_k}^c)<\dfrac{\epsilon}{2^{|k|}}$ and $f|_{F_k}$ is continuous. Now $G=\bigcup_{k \in \mathbb N} {F_k}^c$ is an open set, so it can be expressed as a union of disjoint intervals, that means, $G=\bigcup_{k \in \mathbb N}(a_k,b_k)$. I thought of defining $g:\mathbb R \to \mathbb R$ as
$$g(x)= \begin{cases} \dfrac{x-a_k}{b_k-a_k}f(b_k)+f(a_k) &\text{if }x \in G \\ f(x) &\text{if }x \in G^c \\ \end{cases}$$
I am not sure if this construction works, I don't know what to do for example if $x \in G$ and I have a sequence $x_k \to x$ such that there are infinitely $x_k$'s in $G$ and infinitely $x_k$'s in $G^c$. I would appreciate if someone could help me to show the continuity of $g$ or suggest me how to construct $g$ if my construction doesn't work. Thanks in advance.