Skip to main content
3 of 6
added 4 characters in body
RomanPerekhrest
  • 30.9k
  • 5
  • 47
  • 68

awk approach:

awk 'BEGIN{OFS="\t"; print "pos" OFS "COL1"}NR>1{for(i=2;i<=NF;i++) print $1,$i}' real2.txt

The output:

pos COL1
18691441    C
18691441    A
18691441    G
18691572    G
18691572    C
18691572    G
18691620    A
18691620    T
18691620    G
18691716    C
18691716    G
18691716    C

OFS="\t" - output field separator

print "pos" OFS "COL1" - prints header line

NR>1 - start processing from 2nd line

for(i=2;i<=NF;i++) print $1,$i - printing each column (COL...) value "rowwise" regarding to respective pos column value

RomanPerekhrest
  • 30.9k
  • 5
  • 47
  • 68