Converting txt file in csv

HI All,

I have a text file memory.txt which has following values.

   Average:       822387   7346605     89.93    288845   4176593   2044589     51883      2.47      7600 

i want to convert this file in csv format and i am using following command to do it.

  sed s/_/\./g < memory.txt | awk -F. '{ print $1","$2","$3","$4}' > test.csv 

but I am getting output in just 3 columns. I want every value to be printed in new column.

I have also used this one but result is not accurate.

awk -F_ '{ print $1","$2","$3}' < memory.txt >  MemoryTemp.csv

plz tell me where i am doing wrong. i got this code from google.

Thanks in advance.

Since the 1st awk code just handles only first 3 fields you only get first 3 fields. There is also a substitution of underscores where there aren't any. So a following underscore as field separator is not working either. This code does not fit to your question at all. You can try this one - I've chosen the semicolon as separator:

$> sed 's/[[:space:]]\+/;/g' memory.txt > memory.csv
$> cat memory.csv
Average:;822387;7346605;89.93;288845;4176593;2044589;51883;2.47;7600

Hi,
Try this,

tr -s ' ' ',' < inputfile

Hi,

zaxxon: by choosing , (comma) as a separator, i got the required results. so thanks for your input.

sed 's/[[:space:]]\+/,/g' memory.txt > memory.csv

pravin27: your code is also working so thanks for your efforts.

Regards,
Kashif.