leed@orstcs.UUCP (leed) (08/09/84)
"" Let us not forget that grep also accepts the meta-characters '<' and '>' for word boundry matching. Yes, it's true that the dictionary is set up with one word per line, but in the more general sense, one could search using: grep '\<am.le\>' any_file_name And this would find 'ample', but not 'trample'. The reason for needing both quotes and the back-slash is that the quotes are to satisfy the shell that the commands are executed in, and the back-slashes are to tell grep that the less-than and greater-than signs are meta-characters. Without the back- slashes, grep thinks you want to match on a real less-than or greater-than sign! From the never-stationary soul of: the masked non-system manager (:~:) (otherwise known as: ...!hplabs!hp-pcd!orstcs!leed -- W. Lee Duncan)
harris@imsvax.UUCP (08/14/84)
Our version of grep does not seem to work properly. ( grep 'am.le' /usr/dict/words ) finds words longer than 5 characters. It is my understanding that '.' should only match one character. Harris Reavin UUCP: {umcp-cs!eneevax || seismo!rlgvax!elsie}!imsvax!harris
elvy@harvard.ARPA (Marc Elvy) (08/15/84)
I think that grep is still working correctly. It is my understanding that grep will match any pattern you give it, wherever it appears within a line (or word). Therefore, "grep am.le /usr/dict/words" matches amble and ample, because they match the specification exactly, AND amulet and bramble, because the pattern exists within the words. In all cases, the dot IS only matching one character. In order to match words of the exact length of the pattern, you might consider using the -w switch, which indicates to grep that it should print only a word which matches in its entirety (rather like <word> in ex). Therefore, "grep -w am.le /usr/dict/words" prints the five-character words for which you are looking. Marc Marc A. Elvy ( elvy@harvard.{arpa,uucp} ) Aiken Computation Laboratory Harvard University
gwyn@brl-tgr.ARPA (Doug Gwyn <gwyn>) (08/16/84)
Or, anchor the match using ^ and $.
cmf@cwruecmp.UUCP (Carl Fongheiser) (08/17/84)
Well, one other way to make sure you match only 5-character words is to say something like this: grep '^am.le$' /usr/dict/words This makes sure the string matching the pattern starts at the beginning of the line, and ends on the end of the line. Carl Fongheiser ...!decvax!cwruecmp!cmf
mcnabb@uiucdcsb.UUCP (08/17/84)
#R:imsvax:-22200:uiucdcsb:19300022:000:208 uiucdcsb!mcnabb Aug 17 08:24:00 1984 Remember, grep looks for a pattern, not for words. It delivers any line containing that pattern (the whole line). The fact that /usr/dict/words is arranged one word per line probably helped to confuse this.
honey@down.FUN (09/01/84)
Ah yes, the Berkeley grep. Too bad they threw away the backtracking feature of the "real" grep (but forgot to mention this on the man page). Peter