[SATLUG] character classes with *

mike perez meekprize at gmail.com
Wed Oct 1 15:37:02 CDT 2014


grep matches whole _lines_ from a file. If you are looking to do in-line
replacement then maybe you should take a look at sed.

http://robots.thoughtbot.com/sed-102-replace-in-place

On Wed, Oct 1, 2014 at 3:27 PM, MaxPower <rudebags at hotmail.com> wrote:

> 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
> aa
> L
> Ly
> Lay
> Laay
> a*
> lap007:~/crap$ grep [abcdez]* test   ##why does this command include
> everything in the file (even the upper case L)?
> aa
> L
> Ly
> Lay
> Laay
> a*
> lap007:~/crap$ grep [a-z]* test  ##while this command excludes everything
> in the file?
> lap007:~/crap$
> lap007:~/crap$ grep [abcde]* test  ## once again total file returned
> aa
> L
> Ly
> Lay
> Laay
> a*
> lap007:~/crap$ grep [abcdef]* test  ##the addition of the letter f returns
> a null set?  buh?
> lap007:~/crap$
>
> 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!
>
> > From: rudebags at hotmail.com
> > To: satlug at satlug.org
> > Date: Wed, 1 Oct 2014 15:21:50 -0500
> > Subject: [SATLUG] character classes with *
> >
> > 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 testaaLLyLayLaaya*
> > lap007:~/crap$ grep [abcdez]* test   ##why does this command include
> everything in the file (even the upper case L)?aaLLyLayLaaya*
> > lap007:~/crap$ grep [a-z]* test  ##while this command excludes
> everything in the file?lap007:~/crap$
> > lap007:~/crap$ grep [abcde]* test  ## once again total file
> returnedaaLLyLayLaaya*
> > lap007:~/crap$ grep [abcdef]* test  ##the addition of the letter f
> returns a null set?  buh?lap007:~/crap$
> >
> > I understand that * isn't being used in its normal way and while I grasp
> the logic behindgrep [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!
> >                                         --
> > _______________________________________________
> > SATLUG mailing list
> > SATLUG at satlug.org
> > http://alamo.satlug.org/mailman/listinfo/satlug to manage/unsubscribe
> > Powered by Rackspace (www.rackspace.com)
>                                           --
> _______________________________________________
> SATLUG mailing list
> SATLUG at satlug.org
> http://alamo.satlug.org/mailman/listinfo/satlug to manage/unsubscribe
> Powered by Rackspace (www.rackspace.com)
>



-- 
-m.a.perez
KF5QVO


More information about the SATLUG mailing list