removing extra double quotes between pipe dilimeter


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting removing extra double quotes between pipe dilimeter
# 1  
Old 05-14-2010
removing extra double quotes between pipe dilimeter

I have a flat file sample like this -
Code:
  "COURSE"|"ddddd    "    "    dddd"|"sssddd
  sdsdsdsdx" dddddddd ffffff
  "aaaaa" dddddddd ffffff
  sdsdsd"|"xxxxxxx"|
  "COURSE"|"ffff    "    "    bbbb"|"lllll"|


The delimiter is pipe character (|) and the text are enclosed in double quotes ("). We need to remove the extra double quotes like for example in the text below remove the extra quotes in red , this should be done in the entire file. Between 2 delimiters LINE STARTS with the word “COURSE”, you cannot have more than two quotes, one beginning and one ending…

"ddddd " " dddd"


I need a solution either in awk/sed script.


I am able to separate fields based on | but not able to cut the extra quotes.

Last edited by radoulov; 05-14-2010 at 03:44 AM.. Reason: Added code tags!
# 2  
Old 05-14-2010
This seems like homework ...
Please read the rules!
# 3  
Old 05-14-2010
Hi
this is not a homework.I am no more a student.
I am able to do this with shell script but am still a beginner in awk/sed

please help
# 4  
Old 05-14-2010
Could you show your shell code?
# 5  
Old 05-14-2010
I tried the following now :
Code:
cat sample | \
  awk -v sep='"' '{
         for(i=1;i<=length($0); i++)
         {
            ch=substr($0,i,1)
            if(ch==sep) {inside=!inside}
            if (inside && ch==" "" ") {continue}
            printf("%s",ch)
         }  }'

doesnt work...

---------- Post updated at 02:31 PM ---------- Previous update was at 01:18 PM ----------

this works :
Code:
sed -e 's/\("|"\)/\@/g' -e 's/\("|\)/@/g' -e 's/"//g' -e 's/@/"|"/g' radar.dat

can you tell me what is the awk for this?

Last edited by radoulov; 05-14-2010 at 06:04 AM.. Reason: Added code tags ...
# 6  
Old 05-14-2010
Are you vishalzone or vishalzone2002 ...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Removing consecutive double quotes

Hi I have a .csv file and when opened in notepad looks like this gggg,nnnn,"last,first","llll""",nnn So, Here I would like the ouput as below gggg,nnnn,"last,first","llll",nnn i.e replace all two double quotes into one. How could I do that? This file is being processed by another... (5 Replies)
Discussion started by: dnat
5 Replies

2. Shell Programming and Scripting

Remove pipe(|) symbol in except the ones which are enclosed in double quotes

I have file with are delimited by pipe(|) symbol, I wanted those to be removed except the ones which are enclosed in double quotes. If your quote file is: |Life is |Beautiful"|"Indeed life |is beautiful too|"|"But unix is fun| is not"|" It should return: Life is Beautiful"|"Indeed life is... (9 Replies)
Discussion started by: Sathyapts
9 Replies

3. Shell Programming and Scripting

Remove pipe(|) symbol ina file, except the ones which are enclosed in double quotes

I have file with are delimited by pipe(|) symbol, I wanted those to be removed except the ones which are enclosed in double quotes. If your quote file is: |Life is |Beautiful"|"Indeed life |is beautiful too|"|"But unix is fun| is not"|" It should return: Life is Beautiful"|"Indeed life is... (1 Reply)
Discussion started by: Sathyapts
1 Replies

4. Shell Programming and Scripting

Replace Double quotes within double quotes in a column with space while loading a CSV file

Hi All, I'm unable to load the data using sql loader where there are double quotes within the double quotes As these are optionally enclosed by double quotes. Sample Data : "221100",138.00,"D","0019/1477","44012075","49938","49938/15043000","Television - 22" Refurbished - Airwave","Supply... (6 Replies)
Discussion started by: mlavanya
6 Replies

5. Shell Programming and Scripting

Convert csv to pipe delimited except the ones in double quotes

I have a csv data file : A,B,C,D,"A,B",E,"GG,H" E,F,G,H,I,J,"S,P" I need to replace all "," with "|" except the ones between double quotes i.e A|B|C|D|"A,B"|E|"GG,H" E|F|G|H|I|J|"S,P" CAn someone assist? (8 Replies)
Discussion started by: Shivdatta
8 Replies

6. Shell Programming and Scripting

How to remove extra double quotes from string in a delimited file??

Hi Unix Gurus.. I am new to Unix. Please help me. The file I am getting is as follows: Input File "2011-07-06 03:53:23","0","I","NOT SET ",,,,"123985","SAW CUT CONCRETE SLAB 20"THICK",,"98.57","","EACH","N" "2011-07-06 03:53:23","0","I","NOT SET ",,,,"204312","ARMAFLEX-1 3/8 X... (2 Replies)
Discussion started by: BICC
2 Replies

7. Shell Programming and Scripting

AWK removing away needed double quotes.

The below code is to convert csv file to pipe delimited. It replaces comma with pipe if it is not in double quotes; If comma is in double quotes it doesnot replace the comma with a pipe. The code works fine except it eat away the double quotes in the output file. BEGIN... (6 Replies)
Discussion started by: pinnacle
6 Replies

8. Shell Programming and Scripting

To Replace comma with Pipe inside double quotes

Hi, I have a requirement to replace the comma's inside the double quotes. The comma's inside the double quotes will get changed dynamically. Input Record: "Washington, DC,Prabhu,aju",New York Output Record: "Washington| DC|Prabhu|aju",New York I tried with the below command but it... (3 Replies)
Discussion started by: prabhutkl
3 Replies

9. UNIX for Dummies Questions & Answers

Removing double quotes in a file

Hi All, I have a tab delimited file where each of the strings have double quotes. The problem is that I have records which are in the following format: "TEXAS" ""HOUSTON"" "123" "" "2625-39-39" ""MAINE"" "" "456" "I" "3737-39-82" I would have to output... (3 Replies)
Discussion started by: kingofprussia
3 Replies

10. Shell Programming and Scripting

sed removing comma inside double quotes

I have a csv file with lines like the followings 123456,"ABC CO., LTD","XXX" 789012,"DEF LIMITED", "XXX" before I bcp this file to database, the comma in "CO.," need to be removed first. My script is cat <filename> | sed 's/"CO.,"/"CO."/g' but it doesn't work. Can anyone here able to... (2 Replies)
Discussion started by: joanneho
2 Replies
Login or Register to Ask a Question