From: Philip Reynolds (phil at domain Redbrick.DCU.IE)
Date: Fri 27 Sep 2002 - 15:48:03 IST
Padraig Brady's [padraig.brady at domain corvil.com] 25 lines of wisdom included:
> Can anyone explain the following
> (there should be no output from any of the greps below).
>
> [pixelbeat ~]$ grep --version
> grep (GNU grep) 2.5.1
> [pixelbeat ~]$ file_ids="1025:243:file1\n243:1025:file2\n243:243:file3\n"
> [pixelbeat ~]$ echo -ne $file_ids | grep -E "(0|1|1025|0):(0|1|1025|0)"
> [pixelbeat ~]$ echo -ne $file_ids | grep -E "(0|1|2|1025|0):(0|1|2|1025|0)"
> 1025:243:file1
This matches
``1025:2'' in the string ``1025:243:file1''
Use:
echo -ne $file_ids | grep -E "^(0|1|2|1025|0):(0|1|2|1025|0):"
> [pixelbeat ~]$ echo -ne $file_ids | grep -E "(0|1|2|1025|0):(0|1|2|1025|0):"
> [pixelbeat ~]$ echo -ne $file_ids | grep -E
> "(0|1|2|3|4|5|6|7|8|9|10|65534|1025|48|0):(0|1|2|3|4|5|6|7|8|9|10|65534|1025|48|0)"
> 1025:243:file1
> 243:1025:file2
> 243:243:file3
Same problem here.
Use:
echo -ne $file_ids | grep -E
"^(0|1|2|3|4|5|6|7|8|9|10|65534|1025|48|0):(0|1|2|3|4|5|6|7|8|9|10|65534|1025|48|0):"
> [pixelbeat ~]$ echo -ne $file_ids | grep -E
> "(0|1|2|3|4|5|6|7|8|9|10|65534|1025|48|0):(0|1|2|3|4|5|6|7|8|9|10|65534|1025|48|0):"
> 243:1025:file2
Same problem here again.
It's matching
``3:1025'' in the string ''243:1025:file2''
Use:
echo -ne $file_ids | grep -E
"^(0|1|2|3|4|5|6|7|8|9|10|65534|1025|48|0):(0|1|2|3|4|5|6|7|8|9|10|65534|1025|48|0):"
You're not doing a full regex matches on the strings, use ^ and $
delimiters appropiately.
-- Philip Reynolds RFC Networks tel: 01 8832063 www.rfc-networks.ie fax: 01 8832041
This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:19:07 GMT