Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I want to grep smb.conf and see only lines which are not commented.

share|improve this question
1  
testparm do this better as this display default values too. –  F. Hauri Jan 11 '13 at 20:08
    
@F.Hauri Thank you. it is working as well. But it is also produce some unneeded (in my case) information, which should be grepped also... –  denys Jan 11 '13 at 20:21

1 Answer 1

up vote 15 down vote accepted
grep "^[^#;]" smb.conf

The first ^ refers to the beginning of the line, so lines with comments starting after the first character will not be excluded. [^#;] means any character which is not # or ;.

share|improve this answer
    
right answer is: cat /etc/samba/smb.conf | grep ^[^#\;] But anyway Thank you –  denys Jan 11 '13 at 20:09
    
Yeah, or you could use "quotes"; I edited that in subsequently. –  goldilocks Jan 11 '13 at 20:11
2  
@denys You're wrong: goldilocks's response in not worst than your. .1 Please avoid using cat ...| syntax!. .2 For whipping empty lines AND lines containing only space, maybe with comments U could use this: grep -v "^ *\(#.*\|\)$" < smb.conf –  F. Hauri Jan 11 '13 at 20:14
3  
@EmanuelBerg It's an useless fork. cat file | grep "blah" implie running two binaries through a fifo, while grep "blah" <file do exactly same and bind file naturaly to grep's STDIN . [bash] useless cat is a full featured subject of search through any search engine! -> blog.sanctum.geek.nz/useless-use-of-cat ... for sample –  F. Hauri Jan 11 '13 at 22:01
1  
It doesn't do exactly the same. It creates 2 processes and a pipe where 1 process is enough. Read the link given in @F.Hauri's last comment. –  rahmu Jan 11 '13 at 22:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.