-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLine_Counter.sh
executable file
·51 lines (36 loc) · 1.46 KB
/
Line_Counter.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
# Initialize totals to 0
total=0
source_subtotal=0
test_subtotal=0
################################################################################
# Find source subtotal
# First, put all .cc and .h files from the source directory in a list.
SOURCE_FILE_LIST=$(find ./src | grep -E "(.h$|.cc$)")
# Now loop through the files, adding the length of each one to the subtotal
for File in $SOURCE_FILE_LIST
do
# Get length of file by counting the number of new lines (^)
line_count=$(grep -c ^ $File)
# Add number of lines to subtotal
let source_subtotal=source_subtotal+line_count
done
################################################################################
# Find test subtotal
# First, put all .cc and .h files from the test directory in a list
TEST_FILE_LIST=$(find ./test | grep -E "(.h$|.cc$)")
# Now loop through the files, adding the length of each one to the subtotal
for File in $TEST_FILE_LIST
do
# Get length of file by counting the number of new lines (^)
line_count=$(grep -c ^ $File)
# Add number of lines to subtotal
let test_subtotal=test_subtotal+line_count
done
################################################################################
# Report totals
Makefile_subtotal=$(grep -c ^ ./Makefile)
let total=source_subtotal+test_subtotal+Makefile_subtotal
printf "lines in Source: %s\n" $source_subtotal
printf "lines in Test: %d\n" $test_subtotal
printf "Total (including Makefile): %d\n" $total