I want to delete anything that follows a %
to the end of the line. Using
cat /tmp/foo.txt | sed 's/%.*$//'
works great with one exception: I want to ignore any escaped percent signs \%
. So with the following file saved as /tmp/foo.txt
abcd %123
xyz \%xyz
xyz \%xyz %123
the output I want is
abcd
xyz \%xyz
xyz \%xyz
What is the appropriate regular exception handling to do this?