I have a tab-separated data and it looks like this:
a 1a,2x,c1
b2 a4,4.6
3c 323
The second column has multiple comma seperated values. I want to get this output:
a 1a
a 2x
a c1
b2 a4
b2 4.6
3c 323
I was able to do it with this python code I wrote:
import sys
f = sys.argv[1]
with open(f) as f:
for line in f:
line = line.strip("\n").split("\t")
genes = line[1].split(",")
for gene in genes:
print(line[0],gene, sep="\t")
I know I can do the same with a bash script but I would like to know how can I do this with a cool bash oneliner, using awk, sed, tr and/or cut without using a for loop.
I couldn't go any further than this:
tr ',' '\n' data