[wellylug] curly csv formatting

jumbophut jumbophut at gmail.com
Tue Jul 13 00:02:40 NZST 2004


On Mon, 12 Jul 2004 23:34:33 +1200, jumbophut  wrote:
> 
> 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.
> 

Replying to my own post, because it can be done with fewer commands
and no jumps:

/^[ \t]*[^,]\+,/ {p; s/^[
\t]*\([^,]\+\),\([^,]\+\),\([^,]\+\),\(.*\)$/\1,\2,\3/; h; }
/^[ \t]*,[ \t]*,/ {s/^[ \t]*,[ \t]*,[ \t]*\(,.*\)$/\1/; H; x; s/\n//; p; }

Should have thought of that on the first go!  Not quite as
aesthetically pleasing though.

(Same as last time - save to /tmp/sed2 and run using sed -n
--file=/tmp/sed2 datafile).

Tony




More information about the wellylug mailing list