grep one result per file

Table of Contents

I use find-grep daily to find a “today in previous journals” (which is one of the only true services Facebook provides, for those who don’t value their privacy). Those entries then go into each day of my daily journal. The trouble is, after you do this for a few years, a big chunk of your daily matches are those same matches from yester-year. I organize my journals by year, so really I just want the first entry that matches a day for each year, and I don’t need the sub-entries. Fortunately Grep has a “just show one result” option that does the trick, with the wrapping find operation handling the “per file” bit.

grep -m

find . -type f -exec grep --color -nH --null -m1 -e -04-07 \{\} +
Tory Anderson avatar
Tory Anderson
Web App Engineer, Digital Humanist, Researcher, Computer Psychologist