Question 13 20 points Write a function named initVowelcount that finds how many
ID: 3738435 • Letter: Q
Question
Question 13 20 points Write a function named initVowelcount that finds how many words on each line of a file start with a vowel. Initvowe1Count should write that number to a corresponding line of an output file. Vowels are the letters 'a', 'e' i', o'and 'u' (either upper or lower case). The function initVowelCount takes two string parameters. 1) inFile is the name of an input file that exists before initVowe 1Count is called 2) outFile is the name of an output file that initVowelCount creates and writes to You may assume that inFile is in the current working directory and you should write outFile to that directory If a line in inFile is empty, initVowelCount should write a corresponding empty line to outFile. For example, if the following is the content of the file run. txt: It's a death trap, it's a suicide rap we gotta get out while we're young Cause tramps like us, baby we were born to run The function cal1: initVowelCount('run.txt, 'runMostFreq.txt') should produce a file named runMostFreq.txt with the contentExplanation / Answer
Hi,
As in question it didn't mention the language, I assume it is in shell scripting.
Please find code
#!/bin/sh
# My first Script
echo "Enter first file name ";
read first
echo "Enter second file name to write";
read second
function initVowelCount()
{
file1=$1
file2=$2
while IFS= read -r line;do
echo $line | sed -r 's/[^AEIOU ]w*//ig' >> $2
done < $1
}
initVowelCount $first $second
Output:
Input file:
$ cat test
ello ate how r u
Ello how ru
23
34
45
56
Run the script:
$ sh help.sh
Enter first file name
test
Enter second file name to write
test2
$ cat test2
ello ate u
Ello
It has printed empty lines aswell when it didn't find vowels.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.