On Fri, Mar 25, 2011 at 02:25:35PM -0700, tytus64 wrote:
> while read line
> do
>     line_num=`expr $line_num + 1`
>     echo $line_num: $line >> ./out.log
> done < $log_file

Although it's not directly related to your question, I feel obliged
to point out that you can increment a variable without forking an
external expr command:

line_num=$((line_num+1))    # POSIX sh compatible

or

((line_num++))              # Bash only

You only need expr when writing for the Bourne shell.

Reply via email to