0

I have a data file that looks like this:

1   .   0   10109   AA  AA
1   .   0   10123   C   CCCT
1   .   0   10133   A   AAC
1   .   0   10134   A   ACAAC
1   .   0   10140   A   ACCCTAAC
1   .   0   10143   C   CTACT
1   rs144773400 0   10144   T   TA
1   .   0   10146   AC  A
1   .   0   10147   G   C

In the instance of "." in the second column, I would like to replace it with a merged output of columns 1 and 4, like this:

1   1:10109 0   10109   AA  AA
1   1:10123 0   10123   C   CCCT
1   1:10133 0   10133   A   AAC
1   1:10134 0   10134   A   ACAAC
1   1:10140 0   10140   A   ACCCTAAC
1   1:10143 0   10143   C   CTACT
1   rs144773400 0   10144   T   TA
1   1:10146 0   10146   AC  A
1   1:10147 0   10147   G   C

I've been attempting to do this with an if/then statement... but I know I have the syntax wrong, I'm just not sure how wrong.

if [$2 -eq "." /data/pathtofile]
then 
    awk '{print $1 ":" $4}'
else 
    awk '{print $2}' >> "/data/cleanfile"
fi 

What am I missing?

mfk534
  • 719
  • 1
  • 9
  • 21

1 Answers1

1

You could do this through awk itself.

awk -v FS="\t" -v OFS="\t" '$2=="."{$2=$1":"$4}{$1=$1}1' file

OR

$ awk '$2=="."{$2=$1":"$4}{$1=$1}1' file
1 1:10109 0 10109 AA AA
1 1:10123 0 10123 C CCCT
1 1:10133 0 10133 A AAC
1 1:10134 0 10134 A ACAAC
1 1:10140 0 10140 A ACCCTAAC
1 1:10143 0 10143 C CTACT
1 rs144773400 0 10144 T TA
1 1:10146 0 10146 AC A
1 1:10147 0 10147 G C
Avinash Raj
  • 172,303
  • 28
  • 230
  • 274