Let $\lambda$ denote the Lebesgue measure on $\mathcal B(\mathbb R)$ and $f\in\mathcal L^1_{\text{loc}}(\lambda)$ with $$\int\varphi f\:{\rm d}\lambda=0\;\;\;\text{for all }\varphi\in C_c(\mathbb R)\tag1.$$
I want to conclude that $\lambda$-a.e. $f=0$.
Let $\mu$ denote the measure with density $|f|$ with respect to $\lambda$. By assumption $$\mu(K)<\infty\;\;\;\text{for all compact }K\subseteq\mathbb R\tag2$$ and hence we know that $C_c(\mathbb R)$ is dense in $L^1(\mu)$. Now, let $(K_n)_{n\in\mathbb N}$ be a nondecreasing of compact subsets of $\mathbb R$ with $\bigcup_{n\in\mathbb N}K_n=\mathbb R$. Obviously, it's sufficent to conclude $\mu(K_n)=0$ for all $n\in\mathbb N$.
How can we show that?
We may observe that $$\int\varphi\operatorname{sgn}f\:{\rm d}\mu=\int\varphi f\:{\rm d}\lambda\;\;\;\text{for all }\varphi\in C_c(\mathbb R)\tag3.$$ Fix $n\in\mathbb N$. Clearly, $1_{K_n}\operatorname{sgn}f\in\mathcal L^1(\mu)$ and hence there is a $(\varphi_m)_{m\in\mathbb N}\subseteq C_c(\mathbb R)$ with $$\left\|\varphi_m-1_{K_n}\operatorname{sgn}f\right\|_{L^1(\mu)}\xrightarrow{m\to\infty}0\tag4.$$ The idea should be now to multiplicate $\varphi_m-1_{K_n}\operatorname{sgn}f$ by $\operatorname{sgn}f$ and use $(3)$. However, is this legitimate? And we only have $\operatorname{x}\operatorname{x}=1$ if $x\ne 0$, which could be problematic …
Best Answer
All you need is the following lemma: If $g_n\to g$ in $L^1(\mu),$ and $b$ is bounded and measurable on $\mathbb R,$ then $bg_n\to bg$ in $L^1(\mu).$
Proof: Suppose $|b|\le M$ everwhere. Then
$$\int_{\mathbb R} |bg_n-bg|\, d \mu = \int_{\mathbb R} |b| |g_n-g|\, d \mu \le M\int_{\mathbb R} |g_n-g|\, d \mu \to 0.$$
In your problem we have $\varphi_n \to 1_K\operatorname{sgn}f$ in $L^1(\mu)$ and $b= \operatorname{sgn}f.$ By the lemma,
$$(\operatorname{sgn}f)\varphi_n \to \operatorname{sgn}f\cdot(1_K\operatorname{sgn}f) = 1_K\cdot 1_{\{f\ne 0\}}\,\, \text {in } L^1(\mu).$$
Using your $(3),$ we thus obtain
$$0 = \int_{K\cap \{f\ne 0\}}|f|\,d\lambda = \int_{K}|f|\,d\lambda.$$
Thus $f=0$ $\lambda$-a.e. on $K.$