Grep only the first match and stop

-m 1 means return the first match in any given file. But it will still continue to search in other files. Also, if there are two or more matched in the same line, all of them will be displayed. You can use head -1 to solve this problem: grep -o -a -m 1 -h -r … Read more

Can grep show only words that match search pattern?

Try grep -o: grep -oh “\w*th\w*” * Edit: matching from Phil’s comment. From the docs: -h, –no-filename Suppress the prefixing of file names on output. This is the default when there is only one file (or only standard input) to search. -o, –only-matching Print only the matched (non-empty) parts of a matching line, with each … Read more