Precision tests of the Standard Model and searches for beyond the Standard Model physics often require nuclear structure input. There has been a tremendous progress in the development of nuclear ab initio techniques capable of providing accurate nuclear wave functions. For the calculation of observables, matrix elements of complicated operators need to be evaluated. Typically, these matrix elements would contain spurious contributions from the center-of-mass (COM) motion. This could be problematic when precision results are sought. Here, we derive a transformation relying on properties of harmonic oscillator wave functions that allows an exact removal of the COM motion contamination applicable to any one-body operator depending on nucleon coordinates and momenta. Resulting many-nucleon matrix elements are translationally invariant provided that the nuclear eigenfunctions factorize as products of the intrinsic and COM components as is the case, e.g., in the no-core shell model approach. An application of the transformation has been recently demonstrated in calculations of the nuclear structure recoil corrections for the beta-decay of 6He.