B.Sc Computer Science with Data analytics
Linux and Shell Programming - Lab
Bharathiar University
Program 2- Write a awk script to find the number of characters, words and lines in a file
Source Code
filename="/home/basictoprotamil/Desktop/shell/sample"
# Use awk to calculate characters, words, and lines
awk '{
# Count characters
ccount += length;
# Count words
wcount += NF;
# Count lines
lcount += 1;
}
END {
printf "Number of characters: %d\n", ccount;
printf "Number of words: %d\n", wcount;
printf "Number of lines: %d\n", lcount;
}' $filename
No comments:
Post a Comment