I remember this from 19th century novel "The Captain's Daughter" by Alexander Pushkin[0]. While the book is fiction, the practice isn't presented as something extraordinary for the mid-18th century and may very well be true. I haven't looked for non-fictional sources.
The second paragraph of the novel reads as follows:
Матушка была еще мною брюхата, как уже я был записан в Семеновский полк сержантом, по милости майора гвардии князя Б., близкого нашего родственника. Если бы паче всякого чаяния матушка родила дочь, то батюшка объявил бы куда следовало о смерти неявившегося сержанта, и дело тем бы и кончилось.
Oddly, in both English translations linked to by the Wikipedia article the mention of pregnancy and handling of the girl situation is just dropped.
In my very imperfect translation:
"My mother was only pregnant with me when through the help of a near relative of ours, Prince B., himself a Major of the Guards, I was already enlisted in Semyonovsky regiment as a Sergeant of the Guards. Were my mother, contrary to the wishes, to give birth to a girl, my father would've notified the regiment of the death of an absent sergeant and that would've been it."
The second paragraph of the novel reads as follows:
Матушка была еще мною брюхата, как уже я был записан в Семеновский полк сержантом, по милости майора гвардии князя Б., близкого нашего родственника. Если бы паче всякого чаяния матушка родила дочь, то батюшка объявил бы куда следовало о смерти неявившегося сержанта, и дело тем бы и кончилось.
Oddly, in both English translations linked to by the Wikipedia article the mention of pregnancy and handling of the girl situation is just dropped.
In my very imperfect translation:
"My mother was only pregnant with me when through the help of a near relative of ours, Prince B., himself a Major of the Guards, I was already enlisted in Semyonovsky regiment as a Sergeant of the Guards. Were my mother, contrary to the wishes, to give birth to a girl, my father would've notified the regiment of the death of an absent sergeant and that would've been it."
[0] https://en.wikipedia.org/wiki/The_Captain%27s_Daughter