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!

Using AWK or JOIN help

Status
Not open for further replies.

apedosmil8

IS-IT--Management
Dec 2, 2007
6
US
I'm having trouble with using the AWK command.

I have 3 tables

Employee Table
21/John Doe/39000/Clerk

21 is the employee ID,

Sales Table
104,9,03:01:2007,21

104 is the item ID, 9 is the quantity, and 21 is the employee ID

Products Table
104:fishing line:0.99

104 is the item ID and 0.99 is the price. There is more then just this for data but I wanted to show the relationship.

What would be the best approach to this? I'm lost, I tried something with Join but now I'm not sure if that's a good idea.

Any ideas?

Thanks
 
Join should be fine but you would have to use it twice. What did you try and how did it fail?

Annihilannic.
 
I tried a AWK command but I got syntax errors. I didn't get far enough to get any results.

I need to get totals from each employee on sales.

Could I do a JOIN twice, then do some kind of math?

Thanks,

Mike
 
Well, since you want to do some calculations on the values you won't be able to just use join for that, so you may as well use awk.

Try reading in the files and storing the data in arrays indexed by the keys of each table. Then you can easily run through the sales table and build up a total for each employee.

This sounds kind of homeworkey, so I'm not just going to post a complete solution!

Annihilannic.
 
Incidentally - is there a reason the three tables have differing field separators? It's not that important but it looks kind of sloppy to me.

Ceci n'est pas une signature
Columb Healy
 
Yes they do, that's how it is presented. I tried doing join but it doesn't seem to work since the field separators are different. What I would like to do is do a join, then use variables for each space, maybe to do a find/replace so I can make them all the same.

Does that sound like it would work?

Thanks,

Mike
 
apedosmil8 said:
maybe to do a find/replace so I can make them all the same.
man tr

Ceci n'est pas une signature
Columb Healy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top