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

Ken Alexander kenry at alexandertech.biz
Wed Mar 7 16:16:17 EST 2007


I'm not sure I know what you mean by columned output. Since the file is 
delimited, it's already in columns. If you want to change the delimiter, 
I would suggest using tr or sed instead of awk.

That said ...
FS is field separator used in the input file. OFS is the field separator 
for the output.

So if I wanted to take comma delimited input and output to tab delimited --
    echo "hello,world" | awk 'BEGIN {FS="," ; OFS="\t"} {print $1,$2}'
will print  hello<tab>world.

hope that helps

> Message-ID:
> 	<7a3a8e4d0703070858h3836c0cbub195eb9e69ed903c at mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
> 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
>   




More information about the Ale mailing list