Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script error 1

Status
Not open for further replies.

lambros

Programmer
Oct 10, 2002
42
US
Hi this is probabaly a simple error but I just cant get this part of my script to run, it looks as follows....

{
found=0;
if ( $0 ~ /Test/ )
for(i in ARRAY)
if(match($0, i))
print $1

( It's working fine to here - then at this poing I need to get the Value of $1 ( this is the very first value in $0 - if it matches.... ) and pass it down to the next part... i.e. d=0 part )

reg[0]=$1
found++
}

{
d = 0
for ( j in reg )
if(match($0, j))
if ( $0 ~ j && $0 ~ /try again/ )
print
d++
}


Hope I have made this clear - I have been trying to get this working for some time using arrays etc. to no avail.

Lambros
 
Hi lambros,

It looks like part of the problem is the reg[0]=$1

AWK does not work the same as 'C' when it comes to arrays.

Try changing the zero to one:

reg[1]=$1


If the error persists, please post some example input and
what the output should look like.



flogrr
flogr@yahoo.com

 
Hi flogrr,

This is part of the input

(13/Oct/2002:15:22:57 ) try again : 'server name'
(13/Oct/2002:15:22:57 ) Session::funcid()
(13/Oct/2002:15:22:57 ) No (No rules fired)
(13/Oct/2002:15:22:57 ) : 'lambros' Test failed.

I am writing a script to find out which users fail, this part is ok, the /Test/ part gets written when the user fail... next I want to put the time stamp ( I know this is a poor identifier, but I think i need to use it.... ) into the array & link it to the /try again/ part of the input.... I'm pretty new to unix - let alone awk, & any help on how to do this will be apreciated.

lambros
 
Lambros again... actually I think I can solve my problem If I can find this out...

If I use this command...

if ( $0 ~ /Test/ )

How do I set a variable to the $1 of this output. I've tried

var=$1

but this sets var to every $1 in my input - which is no good to me, I need to set var to $1 of the string returned by /Test/... Can I write some if statement to do this, I've tried arrays etc. but I still can't get this value out.... Thanks
 
Hi lambros,

If I understand what you are trying to do correctly, this should work.

I did not use arrays, but captured the data you wanted in substrings
and put it together as one output record.

Using the sample input you provided, this is the output:

(13/Oct/2002:15:22:57 ) : 'lambros' Test failed. try again : 'server name'

Is this something like the output you need?



awk '

{
if ($0 ~ /try again/) {
ndx = index($0,"try")
try_again = substr($0,ndx)
}

if ($0 ~ /Test/) {
ndx = index($0, ")")
failed = substr($0,ndx+2)
}

if ((failed) && (try_again)) {
print $1" "$2" "failed" "try_again
getline
}

}' inputfile



flogrr
flogr@yahoo.com

 
Thank you flogrr,

I'm going to work on your solution & see how I get on.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top