Print rows based on separator

For below lines in a file.

68078971    dance routine (jess far back corner)    13902786
368079527    dance routine    13902786
368081191    dance routine (jess far back)    13902786

I am looking for output as below

68078971, "dance routine (jess far back corner)",    13902786
368079527 ,   "dance routine" ,  13902786
368081191,    "dance routine (jess far back)",    13902786

Thanks,
Anjan

How is the input separated?

Try

awk     '
    {gsub (/  +/,",&")
     sub  (/  +/,"&\"")
     sub  (/,  +[^ ]*$/,"\"&")
    } 
1
' file
68078971,    "dance routine (jess far back corner)",    13902786
368079527,    "dance routine",    13902786
368081191,    "dance routine (jess far back)",    13902786

I'm afraid I can't replicate your " ," in line two without tremendous effort...

Try:

awk '{$1=$1 ","; $2="\"" $2; $(NF-1)=$(NF-1) "\","}1' file
1 Like

Thanks Scrutinizer it works now.