perl -lne '$a += s/\.java$//}{print"Total java file $ARGV: ", $a||0' java_file
The s///
command returns the number of substitutions which is accumulated in $a
and the result is printed at the end. The $a||0
expression is used in the event there are no .java to be find at the end of lines.
perl -lne '$a += /\.java$/}{print"Total java file $ARGV: ", $a||0' java_file
This time we do a nondestructive test to determine the presence of .java. Rest of the details are the same.