I am thinking how you can replace [^\]% marks but not \% marks in the sed -command of this answer.
I think look-behind is not necessary.
My current Sed command but I think Perl is a must here
cat something | sed 's#%.*</#</#'
which removes also everything after the % sign i.e. all comments in LaTeX but not percentage values.
My unsuccessful Perl attempt
cat something | perl 's#[^\]%.*</#</#'
where I do not know how I make Perl to take the standard output of cat.
Data
------------------------------
Protocol of pre-eclampsia
------------------------------
Monitoring in 90\% cases
Antihypertensives when % this is a comment, please, remove me!
$SBP/DBP > 160/110$; slowly.
------------------------------
Desired output
------------------------------
Protocol of pre-eclampsia
------------------------------
Monitoring in 90\% cases
Antihypertensives when
$SBP/DBP > 160/110$; slowly.
------------------------------
How can you replace % signs but not \%?
If you can do this by Sed, please, comment.
\%%%%%%%%? How does<come into it?\%%%%%...is a comment so everything after second % should be removed.\%, that's what TeX does. However, things like\\%and\\\%are more problematic.%.*<with#<and I wasn't sure if he wanted comments removed or true replacement of all matching characters. I still don't know why there's s<in the code.