Issue
Is there any way to find a word that contains a given string but is not the exact match. For e.g.
# cat t.txt
first line
ind is a shortform of india
I am trying to return the word "india" because it contains the string "ind" but I do not need the exact match. I have tried this...
# grep -o 'ind' t.txt
ind
ind
Solution
Would you please try the following:
grep -Eo '[A-Za-z]+ind|ind[A-Za-z]+' t.txt
Output:
india
The regex [A-Za-z]+ind|ind[A-Za-z]+
matches ind
including the preceding or following alphabets.
Answered By - tshiono Answer Checked By - Robin (WPSolving Admin)