[Solved] Practice Linux Shell Scripting


Consider adding a counter, bump it up on every line, and print the counter with every line.

Also note fixes to set log_file, update to read command.

log_file="/home/user/log.txt"
line_no=0
while read -r line
do
   line_no=$((line_no+1))
   printf "%d. %s\n" $line_no "$line"
done < "$log_file"

One alternative to consider is to call the nl utility, which performs the exact task.

0

solved Practice Linux Shell Scripting