Solved egrep file wildcard

I was trying to find a text string inside of all the files in a directory. I ended up doing it one letter at a time.

Code:
root@E6420:~ # egrep -l '\<firstboot\>' '/etc/rc.d/*'
egrep: /etc/rc.d/*: No such file or directory
root@E6420:~ # egrep -i '\<firstboot\>' /etc/rc.d/f*
root@E6420:~ # egrep -i '\<firstboot\>' /etc/rc.d/g*
/etc/rc.d/growfs:# KEYWORD: firstboot
root@E6420:~ # egrep -i '\<firstboot\>' /etc/rc.d/*.*
egrep: No match.
root@E6420:~ #
So what is the 'all files' wildcard if *.* dont work. Using /f* /g* appears to work from my output. Why not *.* ?
 
I suspect your first command failed because you quoted the filename. Your last command failed because you were looking for files with a full stop/period in their name. This isn't an egrep 'issue', but rather shell globbing.
*.* means "Anything followed by a period followed by anything", so 'a.b', 'qwerty.uiop', 'foo.bar' would all match, but 'foobar' would not.

Code:
root@fbsd-bil:~ # egrep -i '\<firstboot\>' /etc/rc.d/*.*
egrep: No match.
root@fbsd-bil:~ # egrep -i '\<firstboot\>' /etc/rc.d/*
/etc/rc.d/growfs:# KEYWORD: firstboot
root@fbsd-bil:~ # ls /etc/rc.d/ | grep '\.'
root@fbsd-bil:~ #
root@fbsd-bil:~ #
root@fbsd-bil:~ # echo 'firstboot' > /tmp/foo
root@fbsd-bil:~ # echo 'firstboot' > /tmp/foo.bar
root@fbsd-bil:~ # egrep -Hi '\<firstboot\>' /tmp/*.*
/tmp/foo.bar:firstboot
root@fbsd-bil:~ #
root@fbsd-bil:~ # egrep -Hi '\<firstboot\>' /tmp/*
/tmp/foo:firstboot
/tmp/foo.bar:firstboot

In the above, I've shown that your example indeed does not match, but if you use a single asterisk it does. The I show how there are no files that include a period in their file name in /etc/rc.d
After that, I set up an example with 'firstboot' in two files under /tmp, I run the tests again (with -H to show the file name) to demonstrate how the globbing matches the files - see how in the last example it matches both files, but in the penultimate example it only matches the one containing a period on the file name.
 
Back
Top