tab-delimited to csv
Polytropon
freebsd at edvax.de
Mon Feb 16 09:20:24 PST 2009
On Mon, 16 Feb 2009 11:55:50 -0500, John Almberg <jalmberg at identry.com> wrote:
> Can anyone suggest a way to convert a tab-delimited file to csv using
> standard unix utilities? I could whip up a Ruby script to do it, but
> I hate to reinvent the wheel.
I think it's more simple with sed. Use the global substitution
function, such as
% sed "s/\t/:/g"
See that \t or maybe [ \t]* may be the appropriate field delimiter.
Instead of :, take , or . as separator, just as you need.
Another solution could be awk.
% awk '{ gsub("[\t]*", ":", $0); print $0; }'
If you need additional re-ordering, use -F or FS to specify
the field separator, and then printf "%s:%s:%s\n", $2, $1, $3;.
These would be the easiest (I think) substitution approaches.
--
Polytropon
>From Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...
More information about the freebsd-questions
mailing list