在新列中打印大写字母

时间:2015-10-21 05:45:13

标签: bash awk grep uppercase

“file1.txt”如下所示:

_1ss4TG actaaAAAACAAGTAAGCGTAATTCCTCCtagataataaaTTTACTAGTtata
osa-miR5523_L-1R+1  actaaAAAACAAGTAAGacatGAGGAGGAACATATTTACTAGTtata
ath-miR156a-5p  ggaggTGACAGAatgcgtgctcaccctctatctgtcaccccc

我想在第三列打印UPPERCASE,所以它看起来像这样:

_1ss4TG actaaAAAACAAGTAAGCGTAATTCCTCCtagataataaaTTTACTAGTtata   33
osa-miR5523_L-1R+1  actaaAAAACAAGTAAGacatGAGGAGGAACATATTTACTAGTtata 34
ath-miR156a-5p  ggaggTGACAGAatgcgtgctcaccctctatctgtcaccccc  7

我尝试过使用grep和awk,但我没有把它弄好。

1 个答案:

答案 0 :(得分:2)

awk '{NF+=1;$3=length(gensub("[a-z]","","g",$2))}1' b
_1ss4TG actaaAAAACAAGTAAGCGTAATTCCTCCtagataataaaTTTACTAGTtata 33
osa-miR5523_L-1R+1 actaaAAAACAAGTAAGacatGAGGAGGAACATATTTACTAGTtata 34
ath-miR156a-5p ggaggTGACAGAatgcgtgctcaccctctatctgtcaccccc 7