how can I count the number of a letter in each section

character count
letter frequency counter
character count with spaces
count number of characters excel
word counter
character count in word 2016
character count online
twitter character limit

I have a data like this

>sp|Q96A73|P33MX_HUMAN Putative monooxygenase p33MONOX OS=Homo sapiens OX=9606 GN=KIAA1191 PE=1 SV=1
RNDDDDTSVCLGTRQCSWFAGCTNRTWNSSAVPLIGLPNTQDYKWVDRNSGLTWSGNDTCLYSCQNQTKGLLYQLFRNLFCSYGLTEAHGKWRCADASITNDKGHDGHRTPTWWLTGSNLTLSVNNSGLFFLCGNGVYKGFPPKWSGRCGLGYLVPSLTRYLTLNASQITNLRSFIHKVTPHR
>sp|P13674|P4HA1_HUMAN Prolyl 4-hydroxylase subunit alpha-1 OS=Homo sapiens OX=9606 GN=P4HA1 PE=1 SV=2
VECCPNCRGTGMQIRIHQIGPGMVQQIQSVCMECQGHGERISPKDRCKSCNGRKIVREKKILEVHIDKGMKDGQKITFHGEGDQEPGLEPGDIIIVLDQKDHAVFTRRGEDLFMCMDIQLVEALCGFQKPISTLDNRTIVITSHPGQIVKHGDIKCVLNEGMPIYRRPYEKGRLIIEFKVNFPENGFLSPDKLSLLEKLLPERKEVEE
>sp|Q7Z4N8|P4HA3_HUMAN Prolyl 4-hydroxylase subunit alpha-3 OS=Homo sapiens OX=9606 GN=P4HA3 PE=1 SV=1
MTEQMTLRGTLKGHNGWVTQIATTPQFPDMILSASRDKTIIMWKLTRDETNYGIPQRALRGHSHFVSDVVISSDGQFALSGSWDGTLRLWDLTTGTTTRRFVGHTKDVLSVAFSSDNRQIVSGSRDKTIKLWNTLGVCKYTVQDESHSEWVSCVRFSPNSSNPIIVSCGWDKLVKVWNLANCKLK
>sp|P04637|P53_HUMAN Cellular tumor antigen p53 OS=Homo sapiens OX=9606 GN=TP53 PE=1 SV=4
IQVVSRCRLRHTEVLPAEEENDSLGADGTHGAGAMESAAGVLIKLFCVHTKALQDVQIRFQPQL

I am trying to get the number of K in each section , so the output I am trying to get is like this

         K    R
Q96A73   7    11   
P13674   17   13
Q7Z4N8   11   11
P04637   2    4  

I have been trying to do it using

cat mydata.txt | grep -v '^>' | grep -i -e [k] |wc -l

so for example if we look at the first one

          K    R    KK   RR
Q96A73   7    11    0      0
P13674   17   13    1     2
Q7Z4N8   11   11    1     0
P04637   2    4     0     0

Could you please try following.

awk -F'|' '/^>/{val=$2;next} {print val,gsub(/[kK]/,""),gsub(/[rR]/,"")}' Input_file


In case you want to get output of headers too then try following.

awk -F'|' 'BEGIN{print "       K R"}/^>/{val=$2;next} {print val,gsub(/[kK]/,""),gsub(/[rR]/,"")}'  Input_file


EDT1: As per OP's comment in case we want to get count of 2 continous occurences of KK or kk then try following.

awk -F'|' '/^>/{val=$2;next} {print val,gsub(/kk|KK/,""),gsub(/rr|RR/,"")}' Input_file


EDIT2: To get k,kk,r,rr counts use following.

awk -F'|' '/^>/{val=$2;next} {line=$0;print val,gsub(/[kK]/,""),gsub(/[rR]/,""),gsub(/kk|KK/,"",line),gsub(/rr|RR/,"",line)}' Input_file

With headers:

awk -F'|' '
BEGIN{
  print "       k/K\tr/R\tkk/KK\trr/RR"
}
/^>/{
  val=$2
  next
}
{
  line=$0
  print val,gsub(/[kK]/,""),gsub(/[rR]/,""),gsub(/kk|KK/,"",line),gsub(/rr|RR/,"",line)
}' OFS="\t"   Input_file

Output will be as follows.

       k/K      r/R     kk/KK   rr/RR
Q96A73  7       11      0       0
P13674  17      13      1       2
Q7Z4N8  11      11      0       1
P04637  2       4       0       0

How to Count Characters in MS Word, Knowing the character count of a document is important for any business owner. 3. Click "Word Count" in the Proofing section. The Word Count window opens and displays the numbers of characters in the document with and without spaces. Joshua Phillips has done it all when it comes to video games: strategy guides, � Measure the character length after removing every letter s (6 characters). Subtract the adjusted length from the original length. You can then accurately conclude that the number of times the letter s appears in the word Mississippi is four. A real-world use for this technique of counting specific characters is to calculate a word count in Excel.

Using Perl,

 perl -F"\|" -lne ' BEGIN{print "ID   K R"} s/(K|R)/$kv{$1}++/ge; if(not /^>/ ) { print "$x $kv{K} $kv{R}" ;%kv=() } $x=$F[1] '

with inputs

$ cat KR.txt
>sp|Q96A73|P33MX_HUMAN Putative monooxygenase p33MONOX OS=Homo sapiens OX=9606 GN=KIAA1191 PE=1 SV=1
RNDDDDTSVCLGTRQCSWFAGCTNRTWNSSAVPLIGLPNTQDYKWVDRNSGLTWSGNDTCLYSCQNQTKGLLYQLFRNLFCSYGLTEAHGKWRCADASITNDKGHDGHRTPTWWLTGSNLTLSVNNSGLFFLCGNGVYKGFPPKWSGRCGLGYLVPSLTRYLTLNASQITNLRSFIHKVTPHR
>sp|P13674|P4HA1_HUMAN Prolyl 4-hydroxylase subunit alpha-1 OS=Homo sapiens OX=9606 GN=P4HA1 PE=1 SV=2
VECCPNCRGTGMQIRIHQIGPGMVQQIQSVCMECQGHGERISPKDRCKSCNGRKIVREKKILEVHIDKGMKDGQKITFHGEGDQEPGLEPGDIIIVLDQKDHAVFTRRGEDLFMCMDIQLVEALCGFQKPISTLDNRTIVITSHPGQIVKHGDIKCVLNEGMPIYRRPYEKGRLIIEFKVNFPENGFLSPDKLSLLEKLLPERKEVEE
>sp|Q7Z4N8|P4HA3_HUMAN Prolyl 4-hydroxylase subunit alpha-3 OS=Homo sapiens OX=9606 GN=P4HA3 PE=1 SV=1
MTEQMTLRGTLKGHNGWVTQIATTPQFPDMILSASRDKTIIMWKLTRDETNYGIPQRALRGHSHFVSDVVISSDGQFALSGSWDGTLRLWDLTTGTTTRRFVGHTKDVLSVAFSSDNRQIVSGSRDKTIKLWNTLGVCKYTVQDESHSEWVSCVRFSPNSSNPIIVSCGWDKLVKVWNLANCKLK
>sp|P04637|P53_HUMAN Cellular tumor antigen p53 OS=Homo sapiens OX=9606 GN=TP53 PE=1 SV=4
IQVVSRCRLRHTEVLPAEEENDSLGADGTHGAGAMESAAGVLIKLFCVHTKALQDVQIRFQPQL

$  perl -F"\|" -lne ' BEGIN{print "ID   K R"} s/(K|R)/$kv{$1}++/ge; if(not /^>/ ) { print "$x $kv{K} $kv{R}" ;%kv=() } $x=$F[1] ' KR.txt
ID   K R
Q96A73 8 11
P13674 17 13
Q7Z4N8 11 11
P04637 2 4

$

The OP has updated the question.. pls check now

$  perl -F"\|" -lne ' BEGIN{print "ID   K R"} if(not /^>/) { s/(K|R)/$kv{$1}++;$1/ge;s/(KK|RR)/$kv{$1}++/ige; print "$x $kv{K} $kv{R} ",$kv{KK}?$kv{KK}:0," ",$kv{RR}?$
kv{RR}:0 ;%kv=() } $x=$F[1] ' KR.txt
ID   K R
Q96A73 7 11 0 0
P13674 17 13 1 2
Q7Z4N8 11 11 0 1
P04637 2 4 0 0

$

Excel formula: Count specific characters in a range, For each cell in the range, SUBSTITUTE removes all the o's from the text, then LEN calculates the length of the text without o's. This number is then subtracted from� Formula to Count the Number of Occurrences of a Single Character in One Cell =LEN (cell_ref)-LEN (SUBSTITUTE (cell_ref,"a","")) Where cell_ref is the cell reference, and "a" is replaced by the character you want to count.

$ awk '
    BEGIN { FS="|"; OFS="\t"; print "", "K", "R", "KK", "RR" }
    /^>/ { v=$2; next }
    { print v, gsub(/[kK]/,"&"), gsub(/[rR]/,"&"), gsub(/[kK]{2}/,"&"), gsub(/[rR]{2}/,"&") }
' file
        K       R       KK      RR
Q96A73  7       11      0       0
P13674  17      13      1       2
Q7Z4N8  11      11      0       1
P04637  2       4       0       0

Frequency Counter, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z. Data above will be written into the textarea at right, tab-delimited. It can then be pasted into a � When you wish to find the number of cells with text in Excel, the COUNTIF function with an asterisk in the criteria argument is the best and easiest solution: COUNTIF (range, "*") Because the asterisk (*) is a wildcard that matches any sequence of characters, the formula counts all cells that contain any text.

Counting Letters — How to Think like a Computer Scientist , General Solution: Counting All Letters�. Now we will generalize the counting problem and consider how to count the number of times each letter appears in a � To count the number of occurrences of a specific word in your document, you have to get sneaky. Press ctrl-F to open up the navigation pane and then type the word or phrase you want to count. Not only will Word find all occurrences of the word or phrase, it will diaply the count, too.

Count the number of occurrences of each letter in string, Let's assume you have a system where char is eight bit and all the characters you 're trying to count are encoded using a non-negative number. In this case, you� In the “Proofing” section, click “Word Count”. The “Word Count” dialog box displays, as shown in the image at the beginning of this document. The number of pages and words can also be viewed on the status bar at the bottom of the Word window.

How to count characters in Excel: total or specific chars in a cell or , How to count all characters in a range. When it comes to counting a total number � 3. Formula to Count Cells with Specific Text. Now, let’s dig a deeper little bit. Suppose you need to count the cells where you have a specific text. Here is the example. In the below data table, you need to count the cell where you have “John”. And for this, the formula will be: =

Comments
  • I believe(by seeing your attempt) you DO NOT want to consider line which starts from >, can you please confirm your last statement is not clear.'
  • what If I want to calculate the number of KK (means those that are K is close to K?) I am just wondering if I use your command, will I still be able to identify those ?
  • @Learner, sure then change gsub(..) mentioned in above to gsub(/kk|KK/,"") and let me know. It should take care of smalll kk and capital KK.
  • no , I meant counting those that have only two KK next to each other, should I do this ? awk -F'|' '/^>/{val=$2;next} {print val,gsub(/[kK]/,""),gsub(/[rR]/,""),gsub(/[KK]/,"")}' Input_file ??
  • @Learner, yes then use following one awk -F'|' '/^>/{val=$2;next} {print val,gsub(/kk|KK/,""),gsub(/rr|RR/,"")}' Input_file and let me know?
  • It gives me zero, I pasted the results of the output how it should be above, I really appreciate your guide
  • To be very honest I too thought the same :) couldn't add it but. Thanks for adding it sir ++ve
  • @Ed Morton I wish you were my teacher ;-) how can I learn to code like you? I liked your answer already
  • In every situation - keep all your conditions positive and all the code simple. Beyond that just stick to the absolute basics of tight cohesion and loose coupling and the rest is gravy.