[wellylug] curly csv formatting
jumbophut at gmail.com
Mon Jul 12 23:34:33 NZST 2004
On Fri, 09 Jul 2004 11:21:02 +1200, Mark Signal wrote:
> I have to provide a client with a filtered data dump of an old paradox
> database so that they can import the data into their new sap database. I
> have dumped the filtered data into a csv file (110,000 lines) and formatted
> it using my clutsy perl scripting.
I know you've solved the problem by now, but I felt the compelling
need to do this in sed. Why? Well, just because sed is cool.
Save what is below the line to a text file, say /tmp/sed. Then invoke
with: sed -n --file=/tmp/sed datafile
IMHO, the script looks quite beautiful (artistically, not programmatically).
It works for me on this test data:
Smith, John Trevor, 2 March 1934, BA, French and Economics
, , , BCA, Commercial Law
Simpson, Michael Jones, 3 June 1985, BSc, Chemistry
, , , BCA, Management
/^[ \t]*\([^,]\+\),\([^,]\+\),\([^,]\+\),\(.*\)$/b b
/^[ \t]*,[ \t]*,[ \t]*,\(.*\)$/b c
s/^[ \t]*,[ \t]*,[ \t]*\(,.*\)$/\1/
More information about the wellylug