Specify a command / set of commands that displays the number of lines of code in the .c
and .h
files in the current directory, displaying each file in alphabetical order followed by:
and the number of lines in the files, and finally the total of the lines of code. .
An example that might be displayed would be:
main.c: 202
util.c: 124
util.h: 43
TOTAL: 369
After many attempts, my final result of a one-liner command was :
wc -l *.c *.h | awk '{print $2 ": " $1}' | sed "$ s/total/TOTAL/g"
The problem is that i don't know how to sort them alphabetically
without moving the TOTAL
aswell (considering we don't know how many files are in that folder
). I'm not sure if the command above is that efficient so if you have a better one you can include more variations of it.