Quantcast
Channel: Count the occurrences of a string in a file - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 4

Answer by user218374 for Count the occurrences of a string in a file

$
0
0
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.


Viewing all articles
Browse latest Browse all 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>