Friday, January 12, 2024

Program 2 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

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

Program 12 BCA Madras University BCA Object Oriented Programming using C++ Practical Madras University Program 12 Implement a telephone directory using files

  BCA Object Oriented Programming using C++ Practical Madras University  Program 12  Implement a telephone directory using files SOURCE CODE...