Help with grep in Solaris 9
Not sure if this is the correct forum, It not pls point me to the correct one.
I need an explanation of this regular expression:
grep /^[^\#]*sa2/
Noting the following:
If the ^ character is placed at the start of an expression, it matches at the beginning of the string. If placed after an open-square-bracket, [, it means 'not the contents of the square-brackets'. Otherwise it just matches '^'.
and this:
The * character matches zero or more of the preceding character or group.
Does not the above regex say: the statement is true if there are no # character at the beginning of the "line" (the # character somewhere else in the line does not matter) and the string: sa2 can be anywhere within the line irregardless of preceding or trailing characters. The string sa2 does not have to be at the beginning of the line?
Thanks..
[889 byte] By [
farmboy] at [2007-11-26 10:33:00]

# 1
> Not sure if this is the correct forum, It not pls
> point me to the correct one.
>
> I need an explanation of this regular expression:
> grep /^[^\#]*sa2/
> Does not the above regex say: the statement is true
> if there are no # character at the beginning of the
> "line" (the # character somewhere else in the line
> does not matter)
Not quite.
You require a string with the following characteristics:
String "sa2" present,
zero or more additional characters between beginning and sa2,
The additional characters must not be either '\' or '#'.
So the # character may matter elsewhere in the line.
Also there's a more subtle problem depending on if you're truly typing it like that. 'grep' doesn't use slashes to delimit patterns like some other tools would. So really your pattern requires a slash to precede the first character of the line. It can't do that. You'd need to get rid of them to use with grep.
--
Darren