[X-Unix] Semi-newbe question

Eugene list-themacintoshguy at fsck.net
Sun Nov 28 02:22:47 PST 2004


On Sun, Nov 28, 2004 at 10:47:03AM +0100, Xavier Noria wrote:
: 
: On Nov 28, 2004, at 4:30 AM, Russell McGaha wrote:
: 
: >Folks;
: >	I need a few pointers on an appropriate way to do the following:
: >		I've two files, call them file1 & file2.
: >		formated as follows: text1, text2, .... textx [return] ie 
: >		[ascii chr(13)]
: >						textxy, ..., textxx [return]
: >
: >(in other words a csv text file) and I need to take the coma's out and 
: >replace them with returns.
: 
: A couple of questions:
: 
: The tricky part of this is to deal with the escaping rules. What 
: happens when a field has a comma? Is the comma escaped with a 
: backslash?

If it's the "standard" CSV format, the rules are pretty simple.
If the field contains a comma, the field must be delimited with
double-quote characters.  If the field contains double-quote
characters, the embedded double-quote characters are represented
as a pair of double-quote characters.  Example:

	field1: apple
	field2: windoze sucks
	field3: steve ballmer, moron
	field4: all "politicians" suck

the corresponding line would be:

	apple,windoze sucks,"steve ballmer, moron","all ""politicians"" suck"


-- 
Eugene Lee
http://www.coxar.pwp.blueyonder.co.uk/


More information about the X-Unix mailing list