Multiple characters including single quote in delimiter


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Multiple characters including single quote in delimiter
# 1  
Old 06-16-2009
Multiple characters including single quote in delimiter

Hello,
I need to replace the comma to something else between the single quote:

1aaa,bbb,'cc,cc','ddd',1
2aaa,bbb,'ccc','d,d',0

to

1aaa,bbb,'cc<comma>cc','ddd',1
2aaa,bbb,'ccc','d<comma>d',0

Can someone help? Thanks.
# 2  
Old 06-16-2009
see this thread
# 3  
Old 06-17-2009
I think perl magical regular expression is a good resolution for this kind of requirement.

Code:
while(<DATA>){
	s/,(?=[^']*',)/<COMMA>/g;
	print;
}
__DATA__
1aaa,bbb,'cc,cc','ddd,',1
2aaa,'b,bb,','ccc','d,d',0


__OUTPUT__
1aaa,bbb,'cc<COMMA>cc','ddd<COMMA>',1
2aaa,'b<COMMA>bb<COMMA>','ccc','d<COMMA>d',0

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to split string on single quote as delimiter

I have a variable that contains the following string: FPATH=-rw-rw-r-- 1 user1 dba 0 Aug 7 13:14 /app/F11.3/app/cust/exe/filename1.exe' -rw-rw-r-- 1 user1 dba 0 Aug 19 10:09 /app/app/F11.3/app/cust/sql/33211.sql' -rw-r--r-- 1 user1 dba 0 Aug 6 17:20 /app/F11.2/app/01/mrt/file1.mrt' I... (7 Replies)
Discussion started by: mohtashims
7 Replies

2. Shell Programming and Scripting

Single quote _error_.

Hi all... (This is Don's domain.) I have come across an anomaly in sh and dash compared to bash. It involves echoing a character set to a file in sh and dash compared to bash. It is probably easier to show the code and results first. #!/usr/local/bin/dash #!/bin/sh #!/bin/bash echo... (4 Replies)
Discussion started by: wisecracker
4 Replies

3. Shell Programming and Scripting

Replacing all but the first and last double quote in a line with a single quote with awk

From: 1,2,3,4,5,This is a test 6,7,8,9,0,"This, is a test" 1,9,2,8,3,"This is a ""test""" 4,7,3,1,8,"""" To: 1,2,3,4,5,This is a test 6,7,8,9,0,"This; is a test" 1,9,2,8,3,"This is a ''test''" 4,7,3,1,8,"''"Is there an easy syntax I'm overlooking? There will always be an odd number... (5 Replies)
Discussion started by: Michael Stora
5 Replies

4. UNIX for Dummies Questions & Answers

Find delimiter and double quote the field

Hi I have a asterisk (*) delimited file and there are some fields which contain data having asterisk , now i want to double quote the fileds which contain data with asterisk Ex: input file ID*NAME*EMAIL 1*BILL*BILL@AOL.com 2*J*OY*JOY@msn.com in the 2nd record JOY has a asterisk value in... (11 Replies)
Discussion started by: halmstad
11 Replies

5. Shell Programming and Scripting

double quote as the delimiter

I'm trying to extract a column from a csv file with either cut or awk but some of the fields contain comma with them: "Field1","Field2, additional info","Field3",...,"Field17",... If I want to extract column 3 and use comma as the delimiter, I'll actually get the additional info bit but not... (4 Replies)
Discussion started by: ivpz
4 Replies

6. Shell Programming and Scripting

Replace single quote with two single quotes in perl

Hi I want to replace single quote with two single quotes in a perl string. If the string is <It's Simpson's book> It should become <It''s Simpson''s book> (3 Replies)
Discussion started by: DushyantG
3 Replies

7. Shell Programming and Scripting

replacing a quote in some lines with multiple quote fields

i want to replace mistaken quotes in line starting with tag 300 and relocate the quote in the correct position so the input is 223;25 224;20100428064823;1;0;0;0;0;0;0;0;8;1;3;9697;18744;;;;;;;;;;;; 300;X;Event:... (3 Replies)
Discussion started by: wradwan
3 Replies

8. Shell Programming and Scripting

Single/Multiple Line with Special characters - Find & Replace in Unix Script

Hi, I am creating a script to do a find and replace single/multiple lines in a file with any number of lines. I have written a logic in a script that reads a reference file say "findrep" and populates two variables $FIND and $REPLACE print $FIND gives Hi How r $u Rahul() Note:... (0 Replies)
Discussion started by: r_sarnayak
0 Replies

9. Shell Programming and Scripting

Regex in grep to match all lines ending with a double quote (") OR a single quote (')

Hi, I've been trying to write a regex to use in egrep (in a shell script) that'll fetch the names of all the files that match a particular pattern. I expect to match the following line in a file: Name = "abc" The regex I'm using to match the same is: egrep -l '(^) *= *" ** *"$' /PATH_TO_SEARCH... (6 Replies)
Discussion started by: NanJ
6 Replies

10. Shell Programming and Scripting

single quote

Hi I have a shell script with many lines as below: comment on column dcases.proj_seq_num is dcases_1sq; .... .... I want the above script to be as below: comment on column dcases.proj_seq_num is 'dcases_1sq'; I want to have single quotes like that as above for the entire shell... (2 Replies)
Discussion started by: dreams5617
2 Replies
Login or Register to Ask a Question