Count lines and Words in file using Shell Script

Count lines and Words in file using Shell Script

 

Problem Statement : Write a shell script program which can counts the number of lines as well as words present in given file .

Count lines and Words in file using Shell Script program will take a files name as input to the program . Then it will print the number of lines and number of words in that Files.

To count number of words it will use unix wc command .

Number of Lines
wc -l filename

Number of Words
wc -w filename

Number of Characters

wc -c filename

 Count lines and Words in file using Shell Script Code

Count lines and Words in file using Shell Script Output

Sample Output 1

mint@mint ~ $. /script.sh
Enter a file name:
sample
Number of Lines:
4 sample
Number of Words:
12 sample
Number of Characters:
78 sample

Sample Output 2

mint@mint ~ $. /script.sh
Enter a file name:
sample
Number of Lines:
9 sample
Number of Words:
75 sample
Number of Characters:
434 sample

Sample Output 3

mint@mint ~ $. /script.sh
Enter a file name:
sample
Number of Lines:
4 sample
Number of Words:
63 sample
Number of Characters:
355 sample