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"
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"
awk 'END{print NR}' $filename
ReplyDelete