David A. Harding on 3 Jul 2008 16:48:51 -0700


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] Text file to Excel, automated


On Thu, Jul 03, 2008 at 02:17:27PM -0400, JP Vossen wrote:
> bash Cookbook recipe 13.18 "Converting a Date File to CSV":
> $ awk [...]
> $ perl [...]

\begin{nitpick}

Hey!  That's not bash!  That's awk and perl!  This is bash:

$ IFS="^I" ; convert() { i=0 ; for var in $@; do printf \""${var//\"/\"\"}"\"  
let i++  ; [ $i -ne $# ] && printf , || echo ; done } ; while read line 
do convert $line ; done < tab_delimited

Written prettily:

	IFS="^I" 
	convert() { 
		i=0 
		for var in $@
		do 
			printf \""${var//\"/\"\"}"\"  
			let i++ 
			[ $i -ne $# ] && printf , || echo
		done 
		}
	while read line 
	do 
		convert $line
	done < tab_delimited

Note: you will need to convert ^I to a tab in bash. JP probably knows
      how to do that, but some of you might not: press C-v C-i.

\end{nitpick}

\signature{Dave}
-- 
David A. Harding            Website:  http://dtrt.org/
1 (609) 997-0765              Email:  dave@dtrt.org
                        Jabber/XMPP:  dharding@jabber.org
___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug