Hi.
The "\<" and "\>" are necessary for
grep to see as part of the pattern. If you fail to quote them, the shell will remove the backslashes:
Code:
#!/usr/bin/env sh
# @(#) s1 Demonstrate grep with quoted word boundary assertions.
set -o nounset
echo
debug=":"
debug="echo"
## Use local command version for the commands in this demonstration.
echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version bash
echo
FILE=${1-data1}
echo " Input file $FILE:"
cat $FILE
echo
echo " Results from grep -w:"
grep -w aaa $FILE
echo
echo " Results from grep word boundary assertions quoted:"
grep "\<aaa\>" $FILE
echo
echo " Unquoted and quoted backslashes:"
echo \< and "\<"
exit 0
Producing:
Code:
% ./s1
(Versions displayed with local utility "version")
GNU bash 2.05b.0
Input file data1:
aaa bbb ccc
ddd eee ffff
Results from grep -w:
aaa bbb ccc
Results from grep word boundary assertions quoted:
aaa bbb ccc
Unquoted and quoted backslashes:
< and \<
Quoting can be confusing until one practices by writing a lot of commands and shell scripts ... cheers, drl