Date: Wed, 27 Aug 2008 11:38:46 -0500 From: Martin McCormick <martin@dc.cis.okstate.edu> To: freebsd-questions@freebsd.org, Paul Chvostek <paul+fbsd@it.ca> Subject: Re: Regular Expression Trouble Message-ID: <200808271638.m7RGckOP032351@dc.cis.okstate.edu>
next in thread | raw e-mail | index | archive | help
Paul Chvostek writes: > While I agree with others that awk should be used with explicit > recognition of the particular lines, you can still snatch everything > with sed if you want to. In FreeBSD, sed supported extended regex, so: > > sed -nE 's/.*([0-9a-f]{2}(:[0-9a-f]{2}){5}).*/\1/p' > > The "-n" option tells sed not to print the line unless instructed to > explicitely, and the "p" modifier at the end is that instruction. As > for the regex ... well, that's straightforward enough. > > > This is an attempt to isolate every MAC address that > > appears and then sort and count them to see who is having > > trouble or, in some cases, is causing trouble. > > Then you still may want to use awk for some of that... Actually, I have been using awk, but maybe not as efficiently as I could be, judging from the responses. I was hoping that the sed script would recognize 6 pairs of hex digits connected by :'s no matter where they appeared in a line and give me just that pattern match as, in this case, I don't care why the MAC address printed, only that it did and having nothing but MAC's makes the rest of the sorting and counting trivial. Other helpful examples not quoted but much appreciated. . . > Hope this helps. It helps a lot. Awk is one of those things that one can use for years and still not exploit all the good things it has. I am amazed even after years of using UNIX how much genius is packed in to the basic system. One last sed observation. I did fail to use the -E flag so sed didn't know it should be using extended RE's. I will give your examples a try for both sed and awk and see what new capabilities I can come up with. Again, a thousand thanks to you and everyone else for your answers and patience. It is good to see many different ways of solving the same problem. Martin McCormick
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200808271638.m7RGckOP032351>