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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Skip the delimiter with in double quotes and count the number of delimiters during data extract
# 1  
Old 02-03-2015
Linux 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:
Code:
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:
Code:
742433154|SYN\|THESIS MED CHEM PTY. LTD.|C||100.00|22|AB"C\|Corp|"XYZ|CDEF"||

Thanks,
Brahma

Last edited by Don Cragun; 02-03-2015 at 08:47 PM.. Reason: Add CODE tags.
# 2  
Old 02-03-2015
Try:
Code:
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?
Code:
742433154|SYN\|THESIS MED CHEM PTY. LTD.|C||100.00|22|AB"C\|Corp|"XYZ|CDEF"||'

This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 02-03-2015
Linux

Quote:
Originally Posted by Scrutinizer
Try:
Code:
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?
Code:
742433154|SYN\|THESIS MED CHEM PTY. LTD.|C||100.00|22|AB"C\|Corp|"XYZ|CDEF"||'

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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract multiple columns base on double quotes as delimiter

Hi All, I have my data like below "1","abc,db","hac,aron","4","5" Now I need to extract 1,2,4th columns Output should be like "1",abc,db","4" Am trying to use cut command but not able to get the results. Thanks in advance. (4 Replies)
Discussion started by: weknowd
4 Replies

2. Shell Programming and Scripting

Count The Number Of Delimiters using awk or better

What to know the way to count the number of delimiters in each record by ignoring the escape delimiters. Sample Data: 12345678|ABN\|XYZ MED CHEM PTY. LTD.|C||100.00|22|AB"C\|Corp|"XYZ|CDEF"| I'm using awk -F'|' '{ print NF-1 }' command to find the number of delimiters. this command... (8 Replies)
Discussion started by: BrahmaNaiduA
8 Replies

3. Shell Programming and Scripting

Extract data based on 2nd colume having double quotes

i want extract where the 2nd column having "3" or "7". Based on the forums tried like this but it is not working awk -F"," '$2=3;$2=7 {print}' filename Source "1","2","3","4" "1","3","3","4" "1","7","3","4" "1","8","3","4" "1","2","3","4" "1","2","3","4" Output : ... (5 Replies)
Discussion started by: onesuri
5 Replies

4. UNIX for Dummies Questions & Answers

Remove two delimiters, space and double quotes

I would like to know how to replace a space delimiter with a ^_ (\037) delimiter and a double quote delimiter while maintaining the spaces inside the double quotes. The double quote delimiter is only used on text fields. I'd prefer a one-liner, but could handle a function or script that accepts... (4 Replies)
Discussion started by: SteveDWin
4 Replies

5. Shell Programming and Scripting

How to count number of double quotes in bash

Need a little help. I have just a simple string with a lot double quotes in it. I need to be able to parse through this string, and know how many double quotes I have, and where I am, so I can key off every 9th double quote. For example (coding is not complete): #!/bin/bash count=0... (3 Replies)
Discussion started by: Akilleez
3 Replies

6. Shell Programming and Scripting

How to extract specific data and count number containing sets from a file?

Hello everybody! I am quit new here and hope you can help me. Using an awk script I am trying to extract data from several files. The structure of the input files is as follows: TimeStep parameter1 parameter2 parameter3 parameter4 e.g. 1 X Y Z L 1 D H Z I 1 H Y E W 2 D H G F 2 R... (2 Replies)
Discussion started by: Daniel8472
2 Replies

7. Shell Programming and Scripting

how to find the count of commas in a string excluding the ones in double quotes

Hi, my requirement is to find the count of commas in a string excluding the ones in double quotes. For example: If the input string is abc,xyz.com,lmhgdf,"abc, 401 street","tty,stt",45,23,45 The output should be 7 (7 Replies)
Discussion started by: amitshete
7 Replies

8. Shell Programming and Scripting

Inserting double quotes after third delimiter

Hi, I'm trying to insert double quotes right after the third delimiter in a file. Delimiter is ^Z. For example: Input: Oct ^Z 1234 ^Z John ^Z Hello!" Desired Output: Oct ^Z 1234 ^Z John ^Z "Hello!" Any ideas? (1 Reply)
Discussion started by: kangaroo
1 Replies

9. UNIX for Dummies Questions & Answers

How to count number of delimiters in a file name

I have a list of files with names as "FULL_abcd_xyz_timestamp.txt" and "FULL_xx_abcd_xyz_timestamp.txt". I am writing a script with a 'for loop' to take each file, strip the "FULL" and "timestamp" from the file name and do some actions on the contains of the file. So I need to know the number of... (4 Replies)
Discussion started by: ayanbiswas
4 Replies

10. Shell Programming and Scripting

PERL, extract value between double quotes

I know this is probably much simplier than I am making but I need some help please. I have a data file that contains a value on the first line between double quotes ("00043"). I need to assign the value between the first set quotes to a variable in my perl script for comparison analysis. Also,... (6 Replies)
Discussion started by: methos
6 Replies
Login or Register to Ask a Question