-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweek6.6
More file actions
29 lines (22 loc) · 767 Bytes
/
week6.6
File metadata and controls
29 lines (22 loc) · 767 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
6. Write a shell program to count the following in a text file:
● Number of vowels in a given text file
● Number of blank spaces
● Number of characters
● Number of lines
#!/bin/bash
# read the filename from user input
echo "Enter filename:"
read filename
# count the number of vowels in the file
vowels=$(grep -io "[aeiou]" $filename | wc -l)
# count the number of blank spaces in the file
spaces=$(grep -o " " $filename | wc -l)
# count the number of characters in the file
characters=$(wc -m < $filename)
# count the number of lines in the file
lines=$(wc -l < $filename)
# display the results to the user
echo "Number of vowels: $vowels"
echo "Number of blank spaces: $spaces"
echo "Number of characters: $characters"
echo "Number of lines: $lines"