I'm looking for the words gmail
or outlook
in a directory. Although there are some lines commented out with the word gmail
and outlook
in it. How can I grep
for this?
I tried a bunch of things but I imagine it will look something like:
grep "^[^#;]" | egrep -i "gmail|outlook" *.ksh > a.log
Best Answer
With
grep
:-P
activates Perl compatible regular expressions.^(?=...)
defines a capture group which is not part of the pattern (lookahead; a Perl extenstion). The^
means the start of the line.\s
matches any whitespace character,*+
matches the whitespace 0 or more times and is greedy (a Perl extension).[^#]
matches any character which is not a#
.[^#]*
outside the capture group we again match any character which is not a#
0 or more times(gmail|outlook)
finally matchgmail
oroutlook
I made a test file with different examples:
The output is:
Of course, you can run this on all your
*.ksh
files: