------------------------------------------------------------------------
wc: count words, characters & lines of a text file
------------------------------------------------------------------------

$ cat HelloKitty
Hello
My
Name is
Kitty
Honestly!

$ wc HelloKitty
       5       6      34 HelloKitty  
     # lines   words  character

$ wc -l HelloKitty
       5 HelloKitty    #number of lines

------------------------------------------------------------------------
Sometimes you want to capture the number of lines to a bash variable.
------------------------------------------------------------------------
$ wc -l < HelloKitty	#note the explict use of direction
       5                #results in the file name not being printed

$ nlines1=$(wc -l < HelloKitty)           #new style (Korn)      
$ nlines2=`wc -l < HelloKitty`            #old style (bash)

$ echo $nlines1 
      5 

However note that the different (and less usefuL) ouptut when the input 
file is NOT redirected; either old or new style)

$ nlines2=$(wc -l   HelloKitty)           

$ echo $nlines2 
    5 HelloKitty  
In either case, note that the line count has "blank padding". You 
need to "deblank" to use $nlines in, for example, case comparison.

$ echo ${nlines// /}   #does the trick

Another way is to pass this to "xargs" (which strips out \t, \n and \s)
$ nlines=$(wc -l <HelloKitty|xargs)

------------------------------------------------------------------------
using grep to count lines
------------------------------------------------------------------------

$ grep -c "" HelloKitty    
5

------------------------------------------------------------------------
subtleties (last \n can be missing in some files)
------------------------------------------------------------------------

It is possible for a program to not provide \n for the last line. 
This can lead to wasted time as you try to find the missing character or
missing line.

$ echo "1\n2" > a
$ wc a
 2       2       4 a

$ echoi -n "1\n2" >a
$ wc a
 1       2       3 a