I have a tab delimited file in which in every line I have this:
K00001;K00004;K00008 0 0 34 0 0 0 0 0 0 0 0 0 0 0 0 0 36 0 0 52 0 0 0 6 0
I would like to have one row with a unique code and the same sequence of numbers like this:
K00001 0 0 34 0 0 0 0 0 0 0 0 0 0 0 0 0 36 0 0 52 0 0 0 6 0
K00004 0 0 34 0 0 0 0 0 0 0 0 0 0 0 0 0 36 0 0 52 0 0 0 6 0
K00008 0 0 34 0 0 0 0 0 0 0 0 0 0 0 0 0 36 0 0 52 0 0 0 6 0
Best Answer
You can use awk to split the first column:
You split the first column on
;
(split($1,a,";")
) and then you delete it, to print the whole (new) line ($0
) for each item in the array.As suggested in the comment, after the edit, we can see that tabs are used as separator. To use tab as Output Field Separator, you can use
OFS="\t"
, for instance in theBEGIN
part of awk. Besides, an empty field is inserted with$1=""
. So instead of printinga[i]
then$0
, it is better to set$1
toa[i]
and then print$0
: