Skip the delimiter with in double quotes and count the number of delimiters during data extract

Hi All,

I'm stuck-up in finding a way to skip the delimiter which come within double quotes using awk or any other better option. can someone please help me out.

Below are the details:

Delimited: |
Sample data:

742433154|"SYN|THESIS MED CHEM PTY. LTD."|C||100.00|22|"AB""C|Corp"|"""XYZ"|"CDEF"""|""|""'

Output Delimiter count: 10

command need for the below output:

Output:

742433154|SYN\|THESIS MED CHEM PTY. LTD.|C||100.00|22|AB"C\|Corp|"XYZ|CDEF"||

Thanks,
Brahma

Try:

awk '{if(NR%2-1)gsub(/\|/,"\\|"); else if(!NF) $0=RS $0}1' RS=\" ORS= file

There is a single quote at the end of your input, so shouldn't that also be there in your output?

742433154|SYN\|THESIS MED CHEM PTY. LTD.|C||100.00|22|AB"C\|Corp|"XYZ|CDEF"||'
1 Like

Thanks for the quick response.

I don't want single quote also in the output. please help me out and explain the script which you have provided.

Also please let me know how to eliminate the delimiter \| when I count the total delimiters.