Search code examples
awkvcf-variant-call-format

Transpose a column with respect to next column


I have a file (file1.vcf) as like this

chr1 254 . A . 80 . . xxxx xxxxx
chr1 255 . T . 80 . . xxxx xxxxx
chr1 554 . G C 80 . . xxxx xxxxx
chr1 554 . A . 80 . . xxxx xxxxx
chr1 754 . G A 80 . . xxxx xxxxx

Based on the fourth and fifth column value I need to create a new file as like this

>file1
ATCAA

It is important that if some value is on fifth column forth one have to replace with that. I tried with following awk and transpose

 awk '{if ($5==".") print $4 
else print $5}'

but I could able to find a solution for outputting as expected


Solution

  • $ awk '{printf "%s", ($5=="."?$4:$5)}' file
    ATCAA
    

    if you need a newline at the end, add END{print ""}