[SATLUG] character classes with *
rudebags at hotmail.com
Thu Oct 2 09:10:36 CDT 2014
Bruce & Mike, the formatting of my first email was thrown off and kind of munged everything together. Below is what I was actually attempting to convey and what the actual contents of the test file was.
Wes, cool tutorial. I'm not quite there yet with awk and sed, but I do like interpreting the escapes with special characters especially with using brackets in the file to make sure not to use character classes when searching for strings that have brackets in them.
I am trying to understand why grep is behaving in this manner - using character classes without quotations with the asterisk.
This just adds to my confusion:
Earlier when I ran grep [abcde]* test ##which returned everything in the file
grep [abcdef]* test ##which returned nothing
I removed all files in that directory except for the test file, and grep [abcdef]* test then returned everything in the file!
however, grep [a-z]* test still returns nothing at all.
Perhaps just using brackets and a star without quotes is something that should never be done, I am just wanting to know the cause of this behavior, because, yknow, knowledge.
> From: rudebags at hotmail.com
> To: satlug at satlug.org
> Subject: RE: [SATLUG] character classes with *
> Date: Wed, 1 Oct 2014 15:27:48 -0500
> Victim of formatting... Let's see if I fixed it.
> I'm having a bit of a hard time wrapping my head around what is actually going on here. I'm attempting to learn about regular expressions and this use of character classes with * has me befuddled.
> lap007:~/crap$ cat test
> lap007:~/crap$ grep [abcdez]* test ##why does this command include everything in the file (even the upper case L)?
> lap007:~/crap$ grep [a-z]* test ##while this command excludes everything in the file?
> lap007:~/crap$ grep [abcde]* test ## once again total file returned
> lap007:~/crap$ grep [abcdef]* test ##the addition of the letter f returns a null set? buh?
> I understand that * isn't being used in its normal way and while I grasp the logic behind grep [a-z].* test, grep [a-z]\* test, and grep '[a-z]*' the above has me quite miffed.
> Thank you in advance for any clearing of the mud!
More information about the SATLUG