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

Hunter Eidson hunter at gpc.edu
Wed Mar 7 21:20:03 EST 2007


Yeah, you have to know something about the width of your columns to
really make expand work.  It has a -t/--tabs argument that can either
accept a single number to tell it how large to make the tab stops, or if
you know how wide each column should be, you can give it a comma
seperated list of explicit tab sizes.

    --Hunter

Jeff Lightner wrote:
> Interesting - didn't know that command
>
> Just did a test on a two line file - it seemed to properly space words
> (columnize if you will) that were 5 letters or less but on longer words
> it didn't do so well.   
>
> -----Original Message-----
> From: ale-bounces at ale.org [mailto:ale-bounces at ale.org] On Behalf Of
> Hunter Eidson
> Sent: Wednesday, March 07, 2007 4:30 PM
> To: Atlanta Linux Enthusiasts
> Subject: Re: [ale] Converting CSV files to column based flat files with
> awk?
>
> 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
>>   
>>     
>
> _______________________________________________
> Ale mailing list
> 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
>   

-------------- next part --------------
An HTML attachment was scrubbed...




More information about the Ale mailing list