Home > other >  Linux - How to count occurrences of character 'i' in a word (not a file)
Linux - How to count occurrences of character 'i' in a word (not a file)

Time:10-12

How to print number of i occurrences in Pneumonoultramicroscopicsilicovolcanoconiosis ?

I dont know how to approach this with the commands grep and wc

CodePudding user response:

This should do it:

echo "Pneumonoultramicroscopicsilicovolcanoconiosis"|tr -cd 'i'| wc -c

CodePudding user response:

echo "Pneumonoultramicroscopicsilicovolcanoconiosis" | grep -o i | wc -l

CodePudding user response:

$ echo "Pneumonoultramicroscopicsilicovolcanoconiosis" | awk '{print gsub(/i/,"")}'
6
  • Related