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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AWK Newbie - Ignore # in a file 1

Status
Not open for further replies.

kamhart

Technical User
Jan 20, 2004
1
0
0
US
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. [sad] Help! I know this is simple, but I haven't been able to get it to work.

Thanks,
kamhart

it prints out
 
Something like this ?
awk '/^foo =/{
if ($3==8)
print "Rule: Minimum foo length is set to 8 [G]"
else
print "Rule: Minimum foo length is not set to 8 [Y]"
}' /foo.length

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top