Nandakumar
Content Network

You are not logged in.
Click here to login.

Some part of this library is not public. You must register to get exclusive access. If you are already registered, click here to login.


Shell Programming >> 2017

Shell Script to Count the Lines, Words and Characters in a File

By | | License: proprietary


Here is a small shell script that counts the lines, words and characters in a file. Most shell scripts utilize other programs. In this case, it is wc, the standard Unix utility to count words, lines and characters in a file. Without further delay, let's get into the source code. We'll explain it later.

Please note that this article assumes you already know how to write and execute a shell script.

Code
#!/bin/bash

echo -n "Enter the filename: "
read path

read lines words chars filename < <(wc $path)

echo "The file $filename has $lines lines, $words words and $chars chars."

Keywords (click to browse): word-count wc counting file-statistics shell sh bash linux gnu unix script programming command-line

Shell Script to Count the Lines, Words and Characters in a File | Nandakumar Content Network
Copyright © 2015, 2016, 2017 Nandakumar Edamana.