Issue
I have a requirement to search for an exact word and print a line. It is working if I don't have any .
(dots) in the line.
$cat file
test1 ALL=ALL
w.test1 ALL=ALL
$grep -w test1 file
test1 ALL=ALL
w.test1 ALL=ALL
It is giving the second line also and I want only the lines with the exact word test1
.
Solution
Try this:
grep -E "^test1" file
This states that anything that starts with the word test1 as the first line. Now this does not work if you need to fin this in the middle of line but you werent very specific on this. At least in the example given the ^ will work.
Answered By - stevo81989 Answer Checked By - Candace Johnson (WPSolving Volunteer)