How to ignore delimiter between the quotes?

Hi Guys,
I have following script which counts number of tilde in file but i want to count tilde which are field saparator.but my script count tilde between word also what i need is if line is like

abcd~das~1212~fsddf~

so tilde count is = 4
if line like

abcd~das~1212~fsd"~"df~

so tilda count is =4 onlly it should not give count as 5 that means it should ignor ~ between "~" if it comes in between the any word. Please give me solution in my script only.

#!/bin/bash
WORK_DIR=/export/opt/rtrupld/autosys/scripts_old
DATA_DIR=/cdirect/rtrupld/incoming/intellect
DATA_DIR1=/cdirect/rtrupld/incoming/opics
data1=$DATA_DIR/INTELLECT_TOK_MMRTRCASHFLOW*.txt

if [ $var1 = "INTELLECT"  ] &&  [ $var2  = "TOK"  ]
then
  echo"-------------------------------ERROR IN CASHFLOW HANDOFF-------------------------------------------------"
{
nawk -v v1=`grep "INTELLECT_TOK_CASHFLOW_FLD_COUNT"  $propfile | cut -d"=" -f2` -F'~' '{if (NF-1 != v1)
{print "Error in " $0 " at line number "NR " tilde count= " NF-1 }}' $data1
}

Here path just ignore it properties file value of INTELLECT_TOK_CASHFLOW_FLD_COUNT" is take count of tilde

Thanks & Regards,
Ganesh.

Try:

echo 'abcd~das~1212~fsd"~"df~' |perl -pe '$_=()=/\w~/g;'
# echo 'abcd~das~1212~fsd"~"df~' |sed 's/[^\"~\"]//g;s/\"~\"//g;s/.$//'|wc -c
4

Can even be done within a shell

bash$ IN='abcd~das~1212~fsd"~"df~'
bash$ A=${IN//\"~\"/}; arr=( ${A//\~/ } ); echo ${#arr}
4
bash$

But what if the text inside the double quotes contains other characters than tilde. Then you would need something like this:

$ echo 'abcd~das~1212~fsd"yyr~yyr"df~' | awk '{gsub(/"[^"]*"/,x);print gsub(/~/,x)}'
4