Hi.
In regular expressions with
grep, the "." (period, dot, full-stop) matches any single character (except newline), so you will need to provide an escape that
grep will encounter, thereby effectively removing the normal "magic" of the ".".
Use
(with quotes) as that escaped sequence.
Here's an example:
Code:
#!/usr/bin/env sh
# @(#) s1 Demonstrate dot with grep regular expressions.
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 my-nl grep
echo
# Create data file data1
cat >data1 <<EOF
Hello, world.
Two, no dot: Hello, world (this line should not be matched)
Next line empty (this line and the next should not be matched)
Next line just a dot.
.
Last line here.
EOF
echo
echo " Numbered input file:"
my-nl data1
echo
echo " grep with just a dot:"
grep -n . data1
echo
echo " grep with escaped dot, but not quoted:"
grep -n \. data1
echo
echo " grep with escaped dot, double quotes:"
grep -n "\." data1
exit 0
which produces:
Code:
% ./s1
(Versions displayed with local utility "version")
GNU bash 2.05b.0
my-nl (local) 296
grep (GNU grep) 2.5.1
Numbered input file:
==> data1 <==
1 Hello, world.
2 Two, no dot: Hello, world (this line should not be matched)
3 Next line empty (this line and the next should not be matched)
4
5 Next line just a dot.
6 .
7 Last line here.
grep with just a dot:
1:Hello, world.
2:Two, no dot: Hello, world (this line should not be matched)
3:Next line empty (this line and the next should not be matched)
5:Next line just a dot.
6:.
7:Last line here.
grep with escaped dot, but not quoted:
1:Hello, world.
2:Two, no dot: Hello, world (this line should not be matched)
3:Next line empty (this line and the next should not be matched)
5:Next line just a dot.
6:.
7:Last line here.
grep with escaped dot, double quotes:
1:Hello, world.
5:Next line just a dot.
6:.
7:Last line here.
To see the details, run as:
Best wishes ... cheers, drl