If you have a Mac, try the following:
echo 'abcd*' > grepfile echo 'abc$' >> grepfile echo '^abc' >> grepfile echo "fojeiwuroiuwet\nljfajsljkfabcdddjlfkajlkj\nabcaaa\nzzzabc\n" | grep -f grepfile
Here is the version:
$ grep --v grep (BSD grep) 2.5.1-FreeBSD
This is a machine (rMBP of the taste of 2012) that has been constantly updated with Apple software updates, so I am at 10.8.4.
I checked that GNU grep compiled from the source does not suffer from this problem. Indeed, this is version 2.14, which is a set of versions for 2.5.1.
But how can the task of testing some input against a number of regular expressions be achieved, otherwise, without some extremely inefficient loop that produces grep for each regular expression?
Edit: the approach I used to get around this was something like: while read REGEX; do [[ ... =~ $REGEX ]] ... done < regexfile while read REGEX; do [[ ... =~ $REGEX ]] ... done < regexfile .
Question: Is this a known bug with this version of grep? How can we configure our systems to work correctly with the regular expression file for grep?
Update. Some people seem to report that it works great (even with this FreeBSD 2.5.1 grep). What steps can I take to try to figure out which .so / .dylib it can use? Can someone do shasum /usr/bin/grep and say if it works for you? (I'm not sure if this will provide a lot of information, but what I need is that my computer configuration is confused, or if this is some actual problem with this version of the software.)
$ shasum /usr/bin/grep eac59389d09642decbb8551e2c975f795934bfbf /usr/bin/grep
More details:
$ codesign -dvvv /usr/bin/grep Executable=/usr/bin/grep Identifier=com.apple.zgrep Format=Mach-O thin (x86_64) CodeDirectory v=20100 size=224 flags=0x0(none) hashes=6+2 location=embedded Hash type=sha1 size=20 CDHash=93b823c000188f8737653d8333c90a6db9361d70 Signature size=4064 Authority=Software Signing Authority=Apple Code Signing Certification Authority Authority=Apple Root CA Info.plist=not bound Sealed Resources=none Internal requirements count=2 size=208
Further research:
$ gdb /usr/bin/grep GNU gdb 6.3.50-20050815 (Apple version gdb-1824) (Thu Nov 15 10:42:43 UTC 2012) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "x86_64-apple-darwin"...Reading symbols for shared libraries .... done (gdb) start -f grepfile Function "main" not defined. Make breakpoint pending on future shared library load? (y or [n]) Starting program: /usr/bin/grep -f grepfile Reading symbols for shared libraries +++.............................. done abc abc Program received signal EXC_BAD_ACCESS, Could not access memory. Reason: KERN_INVALID_ADDRESS at address: 0x0000000101000000 0x00007fff89b5d1b3 in memchr () (gdb) where
I rebooted the car. It repeats the same in gdb.
segmentation-fault grep bsd freebsd macos
Steven lu
source share