[ale] Converting CSV files to column based flat files with awk?

Hunter Eidson hunter at gpc.edu
Wed Mar 7 16:30:13 EST 2007


How about using expand to solve the tab/spaces problem:

% tr ',' '\t' < infile | expand > outfile

The expand command will replace the tabs w/ spaces, and you can give it 
arguments to adjust the spacing as needed...

--Hunter

Jeff Lightner wrote:
>
> Only problem with that is the columns aren?t. I believe he?s looking 
> for fixed column width?s.
>
> Ale is fun
>
> Auug has alees
>
> Both have the same amount of white space but aren?t really ?columns?.
>
> e.g.
>
> Ale is fun
>
> Auug has alees
>
> Been a while since I needed to do that ? I **think** I used to do it 
> by piping through ?pr?.
>
> ------------------------------------------------------------------------
>
> *From:* ale-bounces at ale.org [mailto:ale-bounces at ale.org] *On Behalf Of 
> *Charles Shapiro
> *Sent:* Wednesday, March 07, 2007 1:27 PM
> *To:* Atlanta Linux Enthusiasts
> *Subject:* Re: [ale] Converting CSV files to column based flat files 
> with awk?
>
> Uh, if it was me I'd be lookin' at tr(1) or sed(1), rather than awk.
>
> It really depends in part on whether you have commas which are escaped 
> in some way in your infile, e.g.
>
> my,very,educated,mother\,and her boyfriend,just,sent,us,nine,pumpkins
>
> If there ain't any commas like this in your infile, then
>
> tr ',' '\t' < infile > outfile will change the delimiters into tabs.
>
> Otherwise, Things could get Interesting.
>
>
> -- CHS
>
> On 3/7/07, *Ned Williams* <nedj10 at gmail.com <mailto:nedj10 at gmail.com>> 
> wrote:
>
> Greeting Ale members,
>
> I need to convert the lines of a csv file into collumned output I 
> think this is a function of awk but I cannot seem to find the right 
> combitnation of FS and RS options to get it done. Any ideas would be 
> greatly appreciated
>
> thanks
>
> Ned
>
>
> _______________________________________________
> Ale mailing list
> Ale at ale.org <mailto:Ale at ale.org>
> http://www.ale.org/mailman/listinfo/ale
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://www.ale.org/mailman/listinfo/ale
>   




More information about the Ale mailing list