How can I include a line until # but without the # when parsing 'sources.list' with regex?

Posted by stwissel on Super User See other posts from Super User or by stwissel
Published on 2012-06-10T14:38:29Z Indexed on 2012/06/10 16:42 UTC
Read the original article Hit count: 185

Filed under:
|
|

I want to parse my sources.list to extract the list of repositories. I have:

## Some comment
deb http://some.vendor.com/ubuntu precise stable
deb-src http://some.vendor.com/ubuntu precise stable
deb http://some.othervendor.com/ubuntu precise experimental # my current favorite

I want:

http://some.vendor.com/ubuntu precise stable
http://some.othervendor.com/ubuntu precise experimental

So I need: only lines with deb at the beginning and until the end of the line or a # character but excluding it.

So far I have:

grep -o "^deb .*"

But how to match # or LineEnd and excluding the #?

© Super User or respective owner

Related posts about bash

Related posts about debian