I have an input file as below:
apple 6
banana 7
goat 8
and I need output as
{6,apple},
{7,banana},
{8,goat}
However, when I run the awk as below, it is printing extra last comma (,). How to avoid that last comma ?
awk '{print "{"$2","$1"},"}' data
{6,apple},
{7,banana},
{8,goat},
Update:
Actually, I needed output like this
{6,apple},
{7,banana},
{8,goat}
]
and when I run
awk '{print "{"$2","$1"},"}' END {print "\t\t]\n}' data
it gives me
{6,apple},
{7,banana},
{8,goat},
]
I don't need the last comma... How to it avoid in this case?