railmaster7 0 Newbie Poster

I'm having trouble with some syntax errors, and also wanted to get an opinion of what I've written will work as needed. I'm writing an awk report script to organize data from a file and calculate the amount of sales. There are 3 kinds of lines that we will need to read, containing, 3, 4, and 5 fields.

lines that describe products have the following fields:

* product id: an integer number
* description: alphanumeric text
* price: floating point number, with 2 significant digits

lines that describe associates have the following fields:

* associate id: an integer number
* first name: alphanumeric text
* last name: alphanumeric text
* salary: an integer number
* position: alphanumeric text

lines that describe sales have the following fields:

* product id: an integer number
* quantity: an integer number
* date: in the form of dd:mm:yyyy
* associate id: an integer number

The script should compute the sale amounts per associate for the year 2009 and print them in a sorted list ranked according to the sales amount.

#! /bin/bash



BEGIN{
	FS= ":"
	print "Lazy Acres, Inc."
	print "-----------------------"
	count = 0
}
{
	NF == 3 
	{
	prodID = $1
	name[prodID] = $2
	cost[prodID] = $3	
	}

	NF == 5
	{
	empID = $1
	empIDs[count] = $1
	lastName[empID] = $2
	firstName[empID] = $3
	salary[empID] = $4
	position[empID] = $5
	sales[empID] = 0
	count++
	}

	NF == 4
	{
	if [ $3 == '/2009/' ]; then	
	sales[$4] += cost[$1] * $2
	fi
	}

	
}
END{
	index = 0
	while ( index <= count )
	do
	print lastName[empIDs[index]]
	index++
	done

}

Any help would be greatly appreciated!
Thanks.

NOTE: the END statement isn't done yet, I just wrote it as a test.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.