I have a file that has random lines of text. My goal is to find a line which occurs exactly n times. So, I decided to:
sort [file] | uniq -c
After executing these commands, I can see that there is some leading whitespace on each line, followed by the count (from uniq).
Now, when I was testing grep (I am new to learning grep, so I wanted to take it step-by-step), this command
sort [file] | uniq -c | grep \s
returned those lines that had the letter 's' in them. But as per my learning, \s
should represent a whitespace character.
But when I quote the \s
,
sort [file] | uniq -c | grep '\s'
it seems like the leading whitespace character on each line is being matched (because 's' characters aren't being highlighted).
My question is, why do I have to quote the \s
(supposing '\s'
is indeed matching the leading whitespace character). Why doesn't \s
work; why is it evaluating to the letter 's'?
Edit: Even \s\+
doesn't yield the expected behavior unless it is enclosed within single quotes. Why do I have to quote the expression for it to work as expected? What do single quotes have to do with this?