D&C GLug - Home Page

[ Date Index ] [ Thread Index ] [ <= Previous by date / thread ] [ Next by date / thread => ]

Re: [LUG] grep/sed print matching group only

 

On 28/12/10 17:19, Gordon Henderson wrote:
I don't think it's stupid at all. You're using the unix principle to do
exactly what it was designed to do - have a program do one thing well.
In this case you have a good program that matches lines based on regular
expressions (grep - which stands for global regular expression fwiw) and
a good program for chopping bits out of lines base on regular
expressions (sed - stream editor) and you're using them together.

http://catb.org/~esr/writings/taoup/html/ch01s06.html

Well that gave me some interesting reading for a couple of hours lol.

I did consider the idea that grep and sed are each doing different jobs. The thing is, in this case, both are doing something very similar, and for the sake of one simple option, I could avoid having to maintain 2 slightly different versions of the same regex.

After all, sed can perform exactly the same job as grep by doing something like "sed '/foo/p'". And grep can do something fairly similar to sed using the -o option. The problem is that this form of sed command doesn't appear to support groups. I'm yet to find any suitable documentation on (e)grep's support of regex groups; it would appear to be very limited.

--
The Mailing List for the Devon & Cornwall LUG
http://mailman.dclug.org.uk/listinfo/list
FAQ: http://www.dcglug.org.uk/listfaq