Answer by George Vasiliou for Count the occurrences of a string in a file
Just for the record, the all time classic awk: awk '/\.java$/{++c}END{print "Total java files:" c}' file If you want to print also those filenames you can change {++c} to {print;++c}.
View ArticleAnswer by user218374 for Count the occurrences of a string in a file
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...
View ArticleAnswer by Kusalananda for Count the occurrences of a string in a file
$ grep -c '\.java$' file 3 The -c flag to grep will make it report the number of lines in the input that matches the pattern. The pattern \.java$ will match any line that ends with .java. $ name="file"...
View ArticleCount the occurrences of a string in a file
I have a file as below. A ctrl/bng/h2ert/scratch/TestAccountService.java A ctrl/bng/h2ert/scratch/TestAccount.java A ctrl/bng/h2ert/scratch/TestT.java A ctrl/bng/h2ert/scratch/TestAccountService.jpg A...
View Article