Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Awk > Re: Help on sea...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 3 Topic 2152 of 2241
Post > Topic >>

Re: Help on search algorithm

by Janis <janis_papanagnou@[EMAIL PROTECTED] > Feb 7, 2008 at 04:51 AM

On 7 Feb., 11:28, di98mase <di98m...@[EMAIL PROTECTED]
> wrote:
> Hi all,
>
> I have a problem. I would like to search trough a file for a pattern.
> How do I make sure that the script does not hang? This is my current
> solution:
>
> /value/
> {

Didn't you mean

  /value/ {

(i.e. bracket on the same line as the action)

> =A0 =A0foundLog=3D0

This variable is never set to any other value.

> =A0 =A0# from this line and forward search for x.
> =A0 while (foundLog=3D=3D0)
> =A0 {
> =A0 =A0 =A0 getline

Don't use getline; awk does that for you implicitly.

> =A0 =A0 =A0 if ($4=3D=3Dexpected value)

Put constant strings in double quotes.

> =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0return 1
> =A0 =A0 =A0 =A0}
> =A0 =A0 }
>
> }

Instead of all that anove you maybe mean...

  /value/ { flag =3D 1 }
  flag && $4 =3D=3D "another value" { exit 1 }


Janis

>
> The problem is that the script hangs when it cant find "value". How
> could I avoid this? I would like to add some check for EOF.
>
> /di98mase




 3 Posts in Topic:
Help on search algorithm
di98mase <di98mase@[EM  2008-02-07 02:28:52 
Re: Help on search algorithm
Janis <janis_papanagno  2008-02-07 04:51:23 
Re: Help on search algorithm
di98mase <di98mase@[EM  2008-02-07 05:45:34 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat May 17 7:12:39 CDT 2008.