Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am trying to look for a string in the first line and if this string is valid I will going down one line and get another validation, if this validation is also ok, i will going down again and print a parameter of if line, here is what a have:
140036.log 102.117.135.00
140036.log 02/27/2009 FAILURE
183422.log 102.117.135.00
183422.log 02/27/2009 SUCCESS
183422.log /CSPGM02_full_refresh//CED/SCED_20090227183439
183321.log 102.117.135.00
183321.log 02/27/2009 SUCCESS
183321.log /physical/switch/CGV/SCGV20090227183341.VM.DATand here is the awk that I want to use but is not working
awk '{
if ($2 = 102.117.135.00)
a=$2
getline
if ($3 = SUCCESS)
getline
print p" "$2}'

A single equal sign assigns a value. To test for a value, you need a double equal sign.
String values need to be in double-quotes, otherwise they are assumed to be a variable.
Following an if-condition, awk assumes only one statement.
if (a==1)
statement1
statement2In the above, statement1 is optional based on value of a. statement2 is not associated with the if-test, and thus will always be executed. If you want both statements to be based on the if-test, then do:
if (a==1)
{statement1
statement2}
In your original code, p" "$2 actually means the variable p followed by a space followed by word2. But p is unassigned, so I am guessing that you wanted a literal p, so I put it inside the quotes.awk '{
if ($2 == "102.117.135.00")
{a=$2
getline
if ($3 == "SUCCESS")
{getline
print "p "$2
}
}
}' file.in
And just for variety, here is a completely different way to code it:awk '{
if ($2 != "102.117.135.00") next
a=$2
getline
if ($3 != "SUCCESS") next
getline
print "p "$2
}' file.in

![]() |
![]() |
![]() |
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |