ssh1% cat temp
sarah
saab
marrrrrrrrra
marrrrrrrtha
ssh1% grep ar*a temp
grep: No match.
Shouldn't this be the output?
sarah saab marrrrrra
I tried using putty and nxclient for Windows 10.
ssh1% cat temp
sarah
saab
marrrrrrrrra
marrrrrrrtha
ssh1% grep ar*a temp
grep: No match.
Shouldn't this be the output?
sarah saab marrrrrra
I tried using putty and nxclient for Windows 10.
You're using csh
, which sees the *
and tries to expand it as a shell glob and fails. That is, it's csh
saying "No match" here, not grep
. Unlike Bourne family shells, csh
won't pass an unexpandable glob pattern on to the command, so you must quote it to get csh
to release it to grep
.
I recommend single quotes here since you aren't trying to interpolate a variable into the string:
% grep 'ar*a' temp
sarah
saab
marrrrrrrrra
Double quotes will also work in this case because your pattern doesn't contain $
, but I recommend using single quotes here anyway. It's a habit worth cultivating to carefully consider which quotes you use in langauges that let you use them semi-interchangeably, such as shell, Perl, etc. We don't need string interpolation here, so we will choose not to use the quoting style that allows it.
You should quote RE patterns under Bourne family shells, too, by the way. As Mike Wagner hints in his comment above, because regular expressions and glob patterns use many of the same special characters, you can sometimes write an RE pattern that just happens to also match some files, and is thus unexpectedly expanded by the shell.
ar*a
matches saab
. *
is zero-or-more. so a
followed by zero-or-more r
s, followed by another a
. The OPs expected output is correct, or would be if he properly quoted the regexp to prevent shell glob expansion. grep 'ar*a' temp
– cas
Oct 31 '15 at 00:45
ssh1% grep ar.*a temp grep: No match.
and ssh1% grep 'ar*a' temp sarah saab marrrrrrrrra
are my results. Why does this not work without the quotes?
– I'm a noob
Oct 31 '15 at 00:46
No match
from csh
, which is what's really going on here, not the glob vs RE issue I originally assumed.
– Warren Young
Oct 31 '15 at 00:52
'some string'
vs "$HOME/filename.txt"
– cas
Oct 31 '15 at 01:02
ls ar*a
? – Mark Wagner Oct 30 '15 at 23:21