grep Getting started with grep Match whole words


Example

Given a file sample:

hello world
ahello here
hello_there

A normal grep for "hello" returns:

$ grep hello sample 
hello world
ahello here
hello_there

Using -w allows to select those lines containing matches that form whole words:

$ grep -w hello sample 
hello world