3
Lines=(find $FILEDIRECTORY -iname "*$FILEENDING" -exec wc -l {} \;)

The User can put in his path and file ending and it should count how many lines each program has... if User just wc -l it prints me out how man files I have with that file ending what I want is:

100
78
45

So from every file the lines

anubhava
  • 761,203
  • 64
  • 569
  • 643
  • I was trinken to use this array and another array which counts the lines that have one-lined comments... but the Look does not work:#counts the percentage of commentslines for (( i=0; i < ${#Lines[*]}; i++ )); do Percentage[i]=$((100*Comments[i]/Lines[i])) echo ${Percentage[i]} done do have maybe any idea why its not working? –  Nov 14 '20 at 14:53

1 Answers1

1

You may use it like this:

find $FILEDIRECTORY -iname "*$FILEENDING" -exec \
sh -c 'for f; do wc -l < "$f"; done' _ {} +

Please understand that:

  • wc -l < file only prints line count without filename
  • + after exec is much more efficient than \; as find tries to pass multiple files in argument.
  • for f is shorthand for for f in "$@"

Altenative Solution:

find $FILEDIRECTORY -iname "*$FILEENDING" -exec grep -hc '^' {} +

If + doesn't work in your find then use:

find $FILEDIRECTORY -iname "*$FILEENDING" -exec grep -hc '^' {} \;
anubhava
  • 761,203
  • 64
  • 569
  • 643