Hi folks,
I tried searchin the forum for info on this, but didn't find anything that matched what I need.
I have a file that has comment lines in the beginning and within the comments is the same name as a variable I need to look at. See the datafile and the awk script below.
Data in file foo.length
# File Name: foo.length
# file is to be used by foo
foo = 0
So in my simple script, I'm looking at each line and trying to print an error message if foo = 0 when the appropriate value is foo = 8 (yes the spaces are inherent in the file.)
My problem is that if I try
script findfoo
awk '/foo/ { print }' /foo.length | awk '
{
if ( $1 == "foo = 0" ) {
print "Rule: Minimum foo length is not set to 8 [Y]"
} else {
print "Rule: Minimum foo length is set to 8 [G]"
}
}'
I get :
Rule: Minimum foo length is not set to 8 [Y]
Rule: Minimum foo length is not set to 8 [Y]
Rule: Minimum foo length is not set to 8 [Y]
I need the output to only print the error messages on the uncommented lines. Help! I know this is simple, but I haven't been able to get it to work.
Thanks,
kamhart
it prints out
I tried searchin the forum for info on this, but didn't find anything that matched what I need.
I have a file that has comment lines in the beginning and within the comments is the same name as a variable I need to look at. See the datafile and the awk script below.
Data in file foo.length
# File Name: foo.length
# file is to be used by foo
foo = 0
So in my simple script, I'm looking at each line and trying to print an error message if foo = 0 when the appropriate value is foo = 8 (yes the spaces are inherent in the file.)
My problem is that if I try
script findfoo
awk '/foo/ { print }' /foo.length | awk '
{
if ( $1 == "foo = 0" ) {
print "Rule: Minimum foo length is not set to 8 [Y]"
} else {
print "Rule: Minimum foo length is set to 8 [G]"
}
}'
I get :
Rule: Minimum foo length is not set to 8 [Y]
Rule: Minimum foo length is not set to 8 [Y]
Rule: Minimum foo length is not set to 8 [Y]
I need the output to only print the error messages on the uncommented lines. Help! I know this is simple, but I haven't been able to get it to work.
Thanks,
kamhart
it prints out