I would like to count the number of N
characters in the second column of a file and then print this count to the third column.
Example input file (tab-separated):
sample1 TCTNG
sample2 CCNGGGGGTN
sample3 GGGNNNTC
Desired output (tab-separated):
sample1 TCTNG 1
sample2 CCNGGGGGTN 2
sample3 GGGNNNTC 3
I can get a messy version doing the following, but I would like a one-liner, preferably in awk
.
> awk -F '\t' '{print $2}' file.txt | awk -FN '{print NF-1}' > NCount.txt
> paste -d '\t' file.txt NCount.txt
sample1 TCTNG
1
sample2 CCNGGGGGTN
2
sample3 GGGNNNTC
3
N
s ?