| Charcoalman (28) | |||
|
1) How do I get the number of times the alphabet appear ? 2) How do i count frequency of 1-letter words, 2-letter words, 3-letter words till 4 letter words. wc - c ? Can anyone guide me on shell prograaming text.txt
| |||
|
|
|||
| Charcoalman (28) | |
| Help ? | |
|
|
|
| Cubbi (1568) | |||
Assuming that by "alphabets" you mean "letters" (alphabets are ordered sets of letters), this could be done in many different ways, here's one, using a shell array ("lengths") to track the number of times the words of each length were encountered, and a string to combine all letters seen ("letters") which is then reprocessed with grep/sort/uniq to calculate the character frequency.
online demo: http://ideone.com/kqMrQ3 PS: I'm not good at shell, there's probably a simpler way | |||
|
Last edited on
|
|||
| Charcoalman (28) | |
|
Thanks, a lil confused though So how is this thing run ? How does it read from text.txt ? Does it work bash letter.sh ? | |
|
Last edited on
|
|
| Charcoalman (28) | |
| test | |
|
|
|
| slumpers (13) | |
|
This looks an awful lot like homework so I won't write a complete script for you. That being said, this looks like a job for regular expressions. Here is a starting point. To count the number of two letter words in your text file, you can do this: cat text.txt |grep -o '\b[A-Za-z]\{2\}\b' |wc -lTo count the number of occurences of 'a' by itself, you can do this: cat text.txt |grep -o '\b[a]\b' |wc -lTo count the number of occurances of 'a' either by itself or in words you can do this: cat text.txt |grep -o 'a' |wc -lHope this helps. | |
|
|
|
| Charcoalman (28) | |
|
it sure does, thanks just a simple question how do we Have an input with a result For instance echo "Number of A Present : " cat text.txt ..... it doesnt seem to work | |
|
|
|