I want grep to grep one word which is having spaces it

Viewed 30123

I would like to grep the word “s a i” (which has spaces in it) in a xyz.txt file which is saved in another directory. I tried to find an answer but I didn’t manage to find any. I have to use the grep command only.

3 Answers

Just add quotes around your grep command:

grep "s a i" "another directory/xyz.txt"

You can escape the space with a backslash:

grep My\ Documents

You can use regular expression:-

grep -E "(s a i)" a.txt
Related