Write an AWK script called avg-line-len.awkthat computes the average number of characters per line from aninput file from user. However, do not consider empty lines. Also,your result should be rounded down to the nearest integer.
Solution
Please find the awk script to find the averagecharacters per line and also the script ignores counting the emptylines.
Script:
awk -v cmd=”$0″ ‘
BEGIN {
if(ARGC != 2)
{
printf(“nUsage: %s<file-name>nn”, cmd);
exit
}
printf(“This script will read the file: %s and printsthe average number of charactersnn”, ARGV[1]);
line = 0;
totalCharacters = 0;
}
#following pattern checks for any character/spaces but not emptyline
/./ {
if(length($0) >= 1)
OR
OR