Help with extracting data within parentheses

This is my input file:

a|b|c(ef)|g|h(km)|p

My output file should look like:

a|b|ef|g|km|p

That is, pipe is the delimiter. The data within pipe must be displayed as it is but if it encounters any data within parentheses, then only the data within parentheses has to be displayed ( the data before parentheses has to be excluded).

I have tried with this code. But its not working.

n=`awk F '|' '{print NF}' input.txt`
for (( i=1; i<=$n; i++ ))
do
  awk -F'|' '{print $($i)}' input.txt | awk -F'(' '{print $2}' > output.txt
done

Kindly help me to solve this problem. Thanks in advance!

Try:

sed 's/[^|]*(\([^)]*\))/\1/g' infile

Thanks a lot. Its working.