Interviews Questions, Algorithms, Aptitude, C Interview Program, C Theory Question, Aptitude Tricks, Test Series,

Friday, 3 May 2019

IOPP Program 1B

Question:
 Write a shell script to determine the number of lines in a given file (without using wc command). 

SOLUTION:

echo "Enter the Filename"
read filename
cline=0

while read  c
do
if [ "$c"=="\n" ]
then
cline=$(( $cline + 1 ))
fi
done < "$filename"
echo "Number of Lines: $cline"

1 comment: