How to grep with a list of words

You need to use the option -f: $ grep -f A B The option -F does a fixed string search where as -f is for specifying a file of patterns. You may want both if the file only contains fixed strings and not regexps. $ grep -Ff A B You may also want the -w … Read more

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