Created
January 27, 2024 23:56
-
-
Save rchatham/0a948ccb8ef64f99a22bac4273540260 to your computer and use it in GitHub Desktop.
Lines Of Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Check if both directory and extension arguments are provided | |
if [ $# -ne 2 ]; then | |
echo "Usage: ./script.sh [directory] [file extension]" | |
exit 1 | |
fi | |
dir=$1 | |
ext=$2 | |
total_lines=0 | |
# find files with the given extension and count the lines | |
while IFS= read -r file; do | |
line_count=$(wc -l < "$file") | |
echo "$file: $line_count" | |
total_lines=$((total_lines + line_count)) | |
done < <(find "$dir" -name "*.$ext") | |
echo "Total lines in .$ext files: $total_lines" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example usage: