double quote as the delimiter


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting double quote as the delimiter
# 1  
Old 08-31-2011
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:

Code:
"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 Field3:

Code:
cut -f3 d, file

Is there any way to specify the double quote as the delimiter instead of comma?

Thank you.

Last edited by radoulov; 08-31-2011 at 06:07 PM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 08-31-2011
Why cant you tell awk to extract the 4th field...which really is "Field 3" in your input data.
# 3  
Old 08-31-2011
Because the number of additional info, hence the number of commas, vary from line to line and there are well over 40k lines
# 4  
Old 08-31-2011
cut can't split on more than one character in a row, but awk can. I'd split on "," doing this:

Code:
awk -v FS="\",\"" '{ print "\"" $2 "\"" }' < datafile

The
Code:
"\""

are to put the deleted double-quotes back in. Leave them out if you don't care.

The first quote in the first field, and the last quote in the last field, won't be deleted.
# 5  
Old 08-31-2011
Quote:
Originally Posted by Corona688
cut can't split on more than one character in a row, but awk can. I'd split on "," doing this:

Code:
awk -v FS="\",\"" '{ print "\"" $2 "\"" }' < datafile

The
Code:
"\""

are to put the deleted double-quotes back in. Leave them out if you don't care.

The first quote in the first field, and the last quote in the last field, won't be deleted.
The back slash!! Smilie I actually tired FS=""," but didn't work. Now it is working. Thanks a lot.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 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

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

3. Shell Programming and Scripting

Replacing Double Quote in Double Quote incsv file

Hi All , We have source data file as csv file and since data could contain commas ,each attribute is quoted into double quotes.However problem is that some of the attributa data also contain double quotes which is converted to double double quote while creating csv file XLs data : ... (2 Replies)
Discussion started by: Shalini Badal
2 Replies

4. Shell Programming and Scripting

Replace double quotes with a single quote within a double quoted string

Hi Froum. I have tried in vain to find a solution for this problem - I'm trying to replace any double quotes within a quoted string with a single quote, leaving everything else as is. I have the following data: Before: ... (32 Replies)
Discussion started by: pchang
32 Replies

5. Shell Programming and Scripting

getting value between double quote

Can somebody supply me with a simple way to get a value between two double quotes? Example: input = ADR base is "/u01/app/oracle" output = /u01/app/oracle Thanks to all who answer (4 Replies)
Discussion started by: BeefStu
4 Replies

6. 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

7. 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

8. Shell Programming and Scripting

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 Replies)
Discussion started by: bgirl
2 Replies

9. Shell Programming and Scripting

double-quote inside double-quote

hey all, i made a simple .sh like this: echo "<style media="screen" type="text/css">@import url("main.css");</style>" but the output is: <style media=screen type=text/css>@import url(main.css);</style> i want to keep double-quotes, can anyone help me? thanks (3 Replies)
Discussion started by: indraf
3 Replies
Login or Register to Ask a Question