[英]Printing and separating columns in awk
我有這樣的文件(VCF)
##fileformat=VCFv4.0
##INFO=<ID=NS,Number=1,Type=Integer,Description="Number of Samples With Data">
##INFO=<ID=DP,Number=1,Type=Integer,Description="Total Depth">
##FILTER=<ID=q10,Description="Quality below 10">
##FILTER=<ID=s50,Description="Less than 50% of samples have data">
##FORMAT=<ID=GT,Number=1,Type=String,Description="Genotype">
##FORMAT=<ID=GQ,Number=1,Type=Integer,Description="Genotype Quality">
##FORMAT=<ID=DP,Number=1,Type=Integer,Description="Read Depth">
##FORMAT=<ID=HQ,Number=2,Type=Integer,Description="Haplotype Quality">
#CHROM POS ID REF ALT QUAL FILTER INFO FORMAT NA00001
Chr02 259 . A . 20 . . GT:DP:A:C:G:T:PP:GQ 0/0:1:0,1:0,0:0,0:0,0:0,26,23,75,33,33,33,47,52,49:23
Chr02 260 . C . 13 . . GT:DP:A:C:G:T:PP:GQ 0/0:1:0,0:0,1:0,0:0,0:24,0,70,17,25,49,43,25,25,44:16
Chr02 261 . C . 13 . . GT:DP:A:C:G:T:PP:GQ 0/0:1:0,0:0,1:0,0:0,0:24,0,194,18,25,49,44,25,25,45:16
Chr02 262 . C A 21 . . GT:DP:A:C:G:T:PP:GQ 0/1:1:0,0:0,1:0,0:0,0:387,0,342,348,25,368,376,25,25,368:25
Chr02 263 . C . 24 . . GT:DP:A:C:G:T:PP:GQ 0/0:2:0,0:1,1:0,0:0,0:541,0,529,495,29,556,508,29,29,499:29
Chr02 264 . A . 31 . . GT:DP:A:C:G:T:PP:GQ 0/0:2:1,1:0,0:0,0:0,0:0,280,192,317,36,36,36,178,302,219:36
Chr02 265 . G C 25 . . GT:DP:A:C:G:T:PP:GQ 0/1:2:0,0:0,0:1,1:0,0:255,414,0,328,284,29,284,29,351,29:29
Chr02 266 . A . 31 . . GT:DP:A:C:G:T:PP:GQ 0/0:2:1,1:0,0:0,0:0,0:0,281,323,440,36,36,36,209,309,315:36
Chr02 267 . C . 24 . . GT:DP:A:C:G:T:PP:GQ 0/0:2:0,0:1,1:0,0:0,0:595,0,541,481,28,567,512,28,28,512:
我只需要像這樣打印第一行和第二行
Chr02:259-259
Chr02:260-260
Chr02:261-261
Chr02:262-262
Chr02:263-263
.
.
.
Chr02:267-267
我在 awk 中嘗試過這個命令
awk '{ OFS = ":" }{print$1,$2,$2}' input.txt
但這對我不起作用
您能否嘗試僅在 GNU awk
中使用所示示例進行跟蹤、編寫和測試。
awk '/^Chr/{print $1":"$2"-"$2}' Input_file
或者,如果您想查找以 Chr 后跟數字開頭的行,請嘗試以下操作。
awk '/^Chr[0-9]+/{print $1":"$2"-"$2}' Input_file
或者,如果您只想留下注釋行,請嘗試以下操作:
awk '!/^#/{print $1":"$2"-"$2}' Input_file
說明:如果行從 Chr(在第一個解決方案中)或 Chr 后跟數字(在第二個解決方案中)或行不從#
(第 3 個解決方案)開始,則只需檢查條件,然后打印第一個字段冒號第二個字段破折號第二個字段。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.