
why awk don't display the results?
Quote:
>> >In article
>> ..
>> >>/HELLO/ {
>> >> initcount = count
>> >> for (i = 1; i <= NF; ++i) count += ($i == "HELLO")
>> >> if (count > initcount) print
>> >>}
>> >But this fails to perform properly for lines like these:
>> >HELLO, CAN I HELP YOU?
>> >She shouted, "HELLO Paul!"
>> >note that the punctuation is included in the field, so $i
>> >may include "HELLO" but not be equal to it. Parsing text
>> >for words is not just a question of fields.
>> Good point. I had debated whether or not to use
>> /(^|[^A-Za-z])HELLO([^A-Za-z]|$)/
>> Perhaps this or some more elaborate variation is necessary.
>> Only the original poster knows for sure.
>I am the original poster and I am new to AWK. Does this:
>/(^|[^A-Za-z])HELLO([^A-Za-z]|$)/
>mean a record that contains the word HELLO, or any character not in A-
>Za-z and HELLO, or any character not in A-Za-z and HELLO and any
>character not in A-Za-z?
It means the string HELLO preceded by the beginning of the record (line
or in some cases field) or some character that isn't a letter, and
followed by the end of the record (line or in some cases field) or some
character that isn't a letter.
I say field because this is a possible form:
$2 ~ /(^|[^A-Za-z])HELLO([^A-Za-z]|$)/
It's an AWK regular expression, and awk has many places where they are
used.
Chuck Demas
Needham, Mass.
--
Eat Healthy | _ _ | Nothing would be done at all,
Die Anyway | v | That no one could find fault with it.