简体   繁体   中英

awk + gsub special characters

G . . PASS VRT=1 GT 0/0 0/0 0/0 0/0 0/0 0/0
G . . PASS VRT=1 GT 0/0 0/0 0/0 0/0 0/0 0/0
C . . PASS VRT=1 GT 0/0 0/0 0/0 0/0 0/0 0/0

I have a file as shown above and i am trying to replace 0/0 with text in column 1.

awk -F'\t' '{ gsub("0/0", $1/$1);}1' OFS="\t" file.txt

The output should look like:

G       .       .       PASS    VRT=1   GT      G/G     G/G     G/G     G/G     G/G     G/G     
G       .       .       PASS    VRT=1   GT      G/G     G/G     G/G     G/G     G/G     G/G     
C       .       .       PASS    VRT=1   GT      C/C     C/C     C/C     C/C     C/C     C/C   

And it throws the error "awk: division by zero". Looks like i am not matching the special characters. Could someone help.

你的意思是 :

awk -F'\t' 'gsub("0/0", $1"/"$1)+1' OFS="\t" file.txt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM