A bash script

Hello,

I want to write a bash script to delete the content after '#'. However, if '#' appears in a string with "", ignore this. For example,

input file:

test #delete
"test #not delete"

Output file:

test
"test #not delete"

Does anyone know how to write this script?

Thanks