Replace odd and even occurrences of a pattern to another same pattern
Another sed
solution:
$ cat ip.txt\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\$ sed -E 's/(\\+)\1\\?/\1/g' ip.txt\\\\\\\\\\\\\\\\\
(\\+)\1\\?
will evenly divide the backslashes, the optional matching at the end will consume the last backslash for odd cases.
If single backslash should be removed instead of being preserved, use
sed -E 's/((\\+)\2)?\\?/\2/g'