I want to find in a configuration file all lines starting with: a. [ b. include c. #include in the order as it is now! I tried grep -e ^[|^include|^#include config.file but it did not work. How is the right syntax for it? bye Ronald Wiplinger -- Check the headers for your unsubscription address For additional commands send e-mail to suse-linux-e-help@suse.com Also check the archives at http://lists.suse.com Please read the FAQs: suse-linux-e-faq@suse.com
Ronald, On Saturday 03 June 2006 21:57, Ronald Wiplinger wrote:
I want to find in a configuration file all lines starting with: a. [ b. include c. #include
This isn't entirely clear. Do you want to find lines that start with any of those things? If so, this will do it: % egrep '^(\[|#?include)' config.file
in the order as it is now!
I tried grep -e ^[|^include|^#include config.file but it did not work.
The left square bracket is special both to the shell and to egrep. The vertical bar is special to the shell and to egrep (but in a way consistent with how you're using it). When using non-trivial egrep, sed or find patterns, it's advisable to simply enclose the entire pattern argument in single quote marks. Then you need to escape those characters special to egrep patterns that you want treated as literal characters (the square bracket, in this case).
How is the right syntax for it?
It looks from your attempt that you do in deed want to find any line that begins with either a left square bracket, the word include or the word include when preceded by a pound sign. In that case, the pattern I gave above will work. I suggest that you might want to be tolerant of white space around the pound sign or before the include, in which case this would be a proper formulation: % egrep '^(\[| *#? *include)' config.file
bye
Ronald Wiplinger
Randall Schulz -- Check the headers for your unsubscription address For additional commands send e-mail to suse-linux-e-help@suse.com Also check the archives at http://lists.suse.com Please read the FAQs: suse-linux-e-faq@suse.com
Ronald, On Saturday 03 June 2006 23:21, Randall R Schulz wrote:
...
I suggest that you might want to be tolerant of white space around the pound sign or before the include, in which case this would be a proper formulation:
% egrep '^(\[| *#? *include)' config.file
To make this pattern work when the white space is either space or tabs, do this: % egrep $'^(\[|[ \t]*#?[ \t]*include)' config.file In this variation, the shell quoting notation $' ... ' is a way of quoting a string in which the usual C-language-style special character escapes are interpreted. In this case, it's used to get the \t sequence to be replaced with a tab character. Also this shows the square brackets being used both as itself (when preceded by a backslash) and as the notation for a "character class" or set of characters any one of which will match at that point in the pattern. Randall Schulz -- Check the headers for your unsubscription address For additional commands send e-mail to suse-linux-e-help@suse.com Also check the archives at http://lists.suse.com Please read the FAQs: suse-linux-e-faq@suse.com
participants (2)
-
Randall R Schulz
-
Ronald Wiplinger