I need to grep the MySQL-error log starting at today's date formatted like:`date +%y%m%d` (140710) And look for all instances of the word partitioned.I've tried various things to no avail. This seemed to work:more +/`date +%y%m%d` mysql-error.log | grep -c partitionedHowever, if the log file doesn't contain any entries from today, then instead of returning zero, it searches the entire file and returns a number for the entire file.I need it to return zero, if there are no entries from today, not grep the entire file and count the results.Is there some better way of doing this, using sed or awk or something?Technically, what I suppose I need to count is } partitioned { followed by a string of alpha numberic characters, }) because portioned { (without any string) } could occur and shouldn't be counted.That's not a strict requirement though. I'd be happy just counting instances of the word partitioned.Here is an example of the log file: 140109 12:25:07 [Note] WSREP: view(view_id(PRIM,c4819ddf-7952-11e3-89fc-4f9f1bfa267f,3) memb {    c4819ddf-7952-11e3-89fc-4f9f1bfa267f,} joined {} left {} partitioned {    f85c2e70-7952-11e3-a759-aa8332246e85,})140109 12:25:07 [Note] WSREP: Shifting JOINED -> SYNCED (TO: 85)
How to count number of instance of a word starting at another word
bash;scripting;grep;search
With GNU sed anhd grep, you can try:sed -n /$(date +%y%m%d)/,\$p file | grep -c partitioned/pattern/,$ matched first pattern to the end of file.With your input:$ sed -n /$(date +%y%m%d)/,\$p 1.txt | grep -c partitioned1Without matching date:$ sed -n /$(date +%y%m%d)/,\$p 1.txt | grep -c partitioned0