Date: Mon, 16 Feb 2009 18:20:02 +0100 From: Polytropon <freebsd@edvax.de> To: John Almberg <jalmberg@identry.com> Cc: freebsd-questions@freebsd.org Subject: Re: tab-delimited to csv Message-ID: <20090216182002.1a5ec0a2.freebsd@edvax.de> In-Reply-To: <A1268853-0066-4604-AB9E-7D45E738BF32@identry.com> References: <A1268853-0066-4604-AB9E-7D45E738BF32@identry.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, 16 Feb 2009 11:55:50 -0500, John Almberg <jalmberg@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, ...
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20090216182002.1a5ec0a2.freebsd>