首页 > 解决方案 > 用于打印单词和编号的 unix shell 脚本。以元音开头的单词

问题描述

编写一个 shell 脚本,它接受文本文件的名称并查找以元音开头的句子数、单词数和单词数。我已经尝试过以下代码。每次我尝试它都会显示错误

**enter code here
echo"Enter File Name:"
read file
lc=$(wc --lines $file)
wc=$(wc --words $file)
vow=$(grep -o -i" [^AEIOUaeiou]" | wc --words $file)
echo "Lines" $lc
echo "Words" $wc
echo "Vowels Words" $vow**

标签: shellunix

解决方案


这里:

echo "Enter File Name:"
read file
lc=$(cat "${file}"|wc -l)
wc=$(cat "${file}"|wc -w)
vow=$(cat "${file}"|grep -o " [AEIOUaeiou][^ ]\+ " |wc -l)
echo "Lines: $lc"
echo "Words: $wc"
echo "Vowels Words: $vow"

推荐阅读