[lug] awk question

D. Frye dafr at peakpeak.com
Tue Jan 28 10:13:21 MST 2003


On Tue, Jan 28, 2003 at 05:38:33PM +0100, rm at fabula.de wrote:
} On Tue, Jan 28, 2003 at 08:55:52AM -0700, Harris, James wrote:
} > > Alright, I have to admit that it took using Excel to come up 
} > > with this one, but
} > > how about importing the data into a spreadsheet, and then 
} > > saving as a tab
} > > delimited file? This would cause:
} > > 
} > > 1,2,"3,4",5  --->  1	2	"3,4"	5
} 
} This would probably be: 1       2        3,4    5
} (no need to protect the ',' character here).

I agree there is no reason to protect it here, but this was the output
of the *.txt file that Excel created in tab delimited format, so it was
transferred to here for display purposes only.

} > 
} > My gosh... The simplicity of it nearly brings a tear to my eye.  Yes, that
} > would do the job quite nicely, in fact.  It's amazing what a different point
} > of view will reveal.  :)
} > 
} 
} Yes, using Exel instead of AWK simplifies the process ;-) 
} But doesn't this just shift the problem? Unless you can be absulutely
} shure that there's no '\t' caharacter in any of the fields your'e left
} with the same problem (and let me tell you: allmost every time i got
} data from users in CSV format there _where_ tabs in it).

I didn't delve too deeply into the format of the exported file, much
less in *nix, so there may be the '\t' issue to deal with. This was a
quick and dirty way to get information needed for a one time
arrangement, but long term it's neither practical nor desireable.

} > Thanks!  I think I'll still try the exercise in pain that John Koontz
} > suggested since I'd ultimately like to automate this... But your
} > recommendation will help me get the initial meat-n-potatoes out today.
} 
} Probably the most stable/secure way to go will be using Perl's CSV-
} Module (see other postings). It comes with the neccessary state machine
} needed for parsing such data.
} 
}   hth Ralf Mattes
} > Thanks for the suggestion!
} > Jim


David



More information about the LUG mailing list