shelllings

a practical way to learn shell
Log | Files | Refs | README | LICENSE

24_grep.sh (1066B)


      1 #!/bin/sh
      2 
      3 # grep is a command that searches for text in files or input.
      4 #
      5 # $ grep "the" LICENSE
      6 #
      7 # It will show you all the times the letters 't', 'h', and 'e' are used
      8 # next to each other. If you want to only find that word we can do this
      9 #
     10 # $ grep -w -i "the" LICENSE     # -w for the word, -i to ignore the
     11 #                                # the case spellings
     12 #
     13 # The common useful options are listed here
     14 #
     15 # -w	matches whole words
     16 # -x	matches whole lines
     17 # -i	ignores case spellings
     18 # -v	invert match findings
     19 # -n	show line numbers
     20 # -c	count matches per line
     21 # -l	prints file names with matches
     22 # -q	quiet, supress the output, used often for true or false findings
     23 # -H	show the filename before a match when matching many files
     24 # -o	prints only the matching part, not whole line
     25 #
     26 # Help me figure out a way where I can find the amount of times the word
     27 # 'the' (in all of its strange uppercases and lowercases) is used in
     28 # the LICENSE file. It seems that I can't get quite an accurate reading.
     29 
     30 grep 'the' LICENSE | wc
     31 
     32 echo "$word_count" # leave be