Converting variable space width data into CSV data in bash

Hi All,

I was wondering how I can convert each line in an input file where fields are separated by variable width spaces into a CSV file. Below is the scenario what I am looking for.

My Input data in inputfile.txt

   19  15657  15685  Sr2dReader                           107.88     105.51  10404  RUNNING

My output should be

19,15657,15685,Sr2dReader,107.88,105.51,10404,RUNNING

Thanks a many for your inputs.

Try

awk '{$1=$1}1' OFS=, infile
1 Like

try this

csv=`cat filename |tr -s " " ","`

works beautifully. Thanks a lot.

---------- Post updated at 12:43 AM ---------- Previous update was at 12:42 AM ----------

thank u.

useless use of cat award

Useless Use of Cat Award

$ tr -s " " "," < input.txt