How would I calculate and display the number of lines and words that are contained in a .sh file?
Asked
Active
Viewed 2.3e+01k times
4 Answers
167
Use the program wc.
To count the number of lines:
-lwc -l myfile.shTo count the number of words:
-wwc -w myfile.sh
See man wc for more options.
unrealapex
- 125
sourav c.
- 46,120
31
As mentioned by souravc, you can use wc for this:
$ wc -w statusToFiles.sh
10 statusToFiles.sh
$ wc -l statusToFiles.sh
6 statusToFiles.sh
To only display the count itself, you can pipe that output to awk, like this:
$ wc -l statusToFiles.sh | awk '{ print $1 }'
6
...or as kos mentioned below:
$ < statusToFiles.sh wc -l
6
Aaron
- 6,764
8
You can also output the entire file with line numbers in front of every line using the command below:
cat -n myfile
Byte Commander
- 110,243
imad
- 89