Version of Lusin's theorem on real line 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.
 A: Your constructions of $g$ definitely works.
To show that $g$ is continuous on $\mathbb R$, there are two cases: for $x\in G$, as $G$ is open and $g$ is linear when restricted to each $(a_k, b_k)$, $g$ is continuous there. 
Assume $x\notin G$. Then as $f$ is continuous on $G^c$, for all $\epsilon >0$ there is $\delta$ so that  
$$(*)\ \ \ \ |f(x) - f(y)| < \epsilon$$
whenever $y\in G^c$ and $|y-x| < \delta$. Now let $k$ so that $(a_k , b_k) \subseteq (x-\delta, x+ \delta)$, then we have by $(*)$ 
$$|f(x) - f(a_k)|, |f(x) - f(b_k)| <\epsilon.$$
But as $g$ is defined as a linear function in $(a_k, b_k)$, for $y\in (a_k, b_k)$ we have (write $y = ta_k + (1-t) b_k$ for some $t\in (0,1)$)
$$\begin{split}
|g(x) - g(y)| &= |f(x) - g(ta_k + (1-t) b_k) \\
&= |f(x) - tf(a_k) - (1-t) f(b_k)| \\
&\le t|f(x) - f(a_k)| + (1-t)|f(x) - f(b_k)| < \epsilon
\end{split}$$
Now for any $k$, if $(a_k, b_k)$ intercept $(x-\delta, x+\delta)$ and is not contained in it, then we can consider $\delta_1 < \delta$ so that 
$$(a_k, b_k) \cap (x-\delta_1, x+\delta_1) = \emptyset.$$
Note that there are at most two $k$'s so that the above holds (intercept but not contained in $(x-\delta, x+\delta)$. Thus for all $y\in (x-\delta_1, x+ \delta_1)$, we have 
$$|g(x) - g(y)|<\epsilon$$
and thus $g$ is continuous at $x$. 
