Bash: Read a file, line by line

The following script will accept from the keyboard a filename, later it will read it and process it line by line.
In this example we will just number the lines, print them and count the total number of lines in the file.

echo Enter the Filename to process
read filename
while read line
	lineNumber=`expr $lineNumber + 1`;
	echo $lineNumber - $line;
echo "Total Lines Number: $lineNumber";

This post is also available in: Greek

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.