Count how many vowels and consonants occur in a string: Difference between revisions
Count how many vowels and consonants occur in a string (view source)
Revision as of 01:23, 1 July 2024
, 6 days agoAdd ed example
No edit summary |
(Add ed example) |
||
Line 662:
count "Now is the time for all good men to come to the aid of their country."
</syntaxhighlight>
=={{header|ed}}==
Uses non-portable [[GNU Ed]] <tt>i</tt> suffix for case-insensitive matching.
<syntaxhighlight lang="sed">
H
,p
,j
s/[^[:alpha:]]//g
# Turn vowels into exclamations and consonants into commas
s/[aeiou]/!/gi
s/[b-df-hj-np-tv-z]/,/gi
# Sort the values to put vovels first
# (repeat as many times as necessary)
s/(,+)(!+)/\2\1/g
s/(,+)(!+)/\2\1/g
s/(,+)(!+)/\2\1/g
s/(,+)(!+)/\2\1/g
s/(,+)(!+)/\2\1/g
s/(,+)(!+)/\2\1/g
s/(,+)(!+)/\2\1/g
s/(,+)(!+)/\2\1/g
s/(,+)(!+)/\2\1/g
s/(,+)(!+)/\2\1/g
s/(,+)(!+)/\2\1/g
s/(,+)(!+)/\2\1/g
s/(,+)(!+)/\2\1/g
s/(,+)(!+)/\2\1/g
s/(,+)(!+)/\2\1/g
s/(,+)(!+)/\2\1/g
s/(,+)(!+)/\2\1/g
s/(,+)(!+)/\2\1/g
s/(,+)(!+)/\2\1/g
s/(,+)(!+)/\2\1/g
# Split vowels and consontants lines
s/!,/!\
,/
,p
Q
</syntaxhighlight>
{{out}}
<pre>$ cat vowels-consonants.ed | ed -lEGs vowels-consonants.input
Now is the time for all good men to come to the aid of their country
!!!!!!!!!!!!!!!!!!!!!!
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,</pre>
And then count the exclamation marks and commas manually?
=={{header|F_Sharp|F#}}==
|