Thursday, February 17, 2022

[SOLVED] grep -w with only space as delimiter

Issue

grep -w uses punctuations and whitespaces as delimiters. 

How can I set grep to only use whitespaces as a delimiter for a word?

id='dv3'>

Solution

If you want to match just spaces: grep -w foo is the same as grep " foo ". If you also want to match line endings or tabs you can start doing things like: grep '\(^\| \)foo\($\| \)', but you're probably better off with perl -ne 'print if /\sfoo\s/'



Answered By - William Pursell
Answer Checked By - Marilyn (WPSolving Volunteer)