Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. fileExt="*.js"
  4.  
  5. allFiles=$(find ./ -name "$fileExt")
  6.  
  7. commentLines=$((perl -ne 'print "$1n" while /(^s+//s*w+)/sg' $allFiles;
  8. perl -0777 -ne 'print "$1n" while /(**.*?*/)/sg' $allFiles) | wc -l)
  9.  
  10. blankLines=$(grep '^[[:space:]]*//' -r --include $fileExt | wc -l)
  11.  
  12. allLines=$(echo $allFiles | xargs wc -l | tail -n 1 | cut -d " " -f 2)
  13.  
  14. echo -e "nTotal comments line is: $commentLines.n
  15. Total blank lines is: $blankLines.n
  16. nTotal all lines is: $allLines."
  17.  
  18. allFiles=$(find ./ -name "$fileExt")
  19.  
  20. commentLines=$((perl -ne 'print "$1n" while /(^s+//s*w+)/sg' $allFiles;
  21. perl -0777 -ne 'print "$1n" while /(**.*?*/)/sg' $allFiles) | wc -l)
  22.  
  23. //this is a comment line
  24.  
  25. function foo(params 1) { // return void
  26.  
  27. }
  28.  
  29. /(^s+//s*w+)/sg
  30.  
  31. /**
  32. * return something
  33. * @param {object} obj
  34. * return void
  35. */
  36.  
  37. perl -0777 -ne 'print "$1n" while /(**.*?*/)/sg' $allFiles
  38.  
  39. grep '^[[:space:]]*//' -r --include $fileExt | wc -l
  40.  
  41. echo $allFiles | xargs wc -l | tail -n 1 | cut -d " " -f 2
  42.  
  43. $ touch a.js b.js
  44. $ fileExt="*.js"
  45. $ find ./ -name $fileExt
  46. find: paths must precede expression: `b.js'
  47. find: possible unquoted pattern after predicate `-name'?
  48.  
  49. dirs=("${@:-.}")
  50.  
  51. allFiles=$(find "${dirs[@]}" -name "$fileExt" -type f)
  52.  
  53. allFiles=()
  54. while IFS= read -r -d ''; do
  55. allFiles+=("$REPLY")
  56. done < <(find ./ -name "$fileExt" -type f -print0)
  57.  
  58. sed -e '!^[[:blank:]]*/**!,!*/!s/.*/\\/'
  59. -e '|^[[:blank:]]*//|!d'
  60.  
  61. cat <<EOF
  62. Total comments lines is: $commentLines.
  63. Total blank lines is: $blankLines.
  64. Total all lines is: $allLines.
  65. EOF
  66. exit
  67.  
  68. #!/bin/bash
  69. set -eu
  70.  
  71. fileExt='*.js'
  72. dirs=("${@:-/usr/lib/nodejs/lodash}")
  73.  
  74. allFiles=()
  75. while IFS= read -r -d ''; do
  76. allFiles+=("$REPLY")
  77. done < <(find "${dirs[@]}" -name "$fileExt" -type f -print0)
  78.  
  79. commentLines=$(sed -e '!^[[:blank:]]*/**!,!*/!s/.*/\\/'
  80. -e '|^[[:blank:]]*//|!d'
  81. "${allFiles[@]}" | wc -l)
  82. blankLines=$(cat "${allFiles[@]}" | grep -c '^[[:blank:]]*$')
  83. allLines=$(cat "${allFiles[@]}" | wc -l)
  84.  
  85. cat <<EOF
  86. Total comment lines is: $commentLines.
  87. Total blank lines is: $blankLines.
  88. Total all lines is: $allLines.
  89. EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement