Get count of lines in scripts (shell)
2015-10-15
88 words
1 min read
If you have tried to get the count of lines in file, the you would know about “nl” or “wc -l”. But as you are aware these give you number of lines with other details as well and you need to post process the number to make sure that you have only number and nothing else. In such cases, it is useful to use the count feature of grep and here is a shorthand to get the count of lines in any shell script:
lines=$(grep -c . <filename>)
Related Articles:
- 2011/05/16 Unix shell script for removing duplicate files
- 2011/01/25 shopt causes bash completion to stop working.
- 2010/09/04 Remove some path from the PATH variable temporarily.
- 2013/11/22 bash – using the vi mode more effectively.
- 2012/03/02 15 Linux Bash History Expansion Examples You Should Know
Authored By Amit Agarwal
Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.