Find the answer to your Linux question:
Results 1 to 2 of 2
Hey folks. I will e very upfront and say i am NOT a good UNIX script writer at ALL. I have to work on a project that will take information ...
  1. #1
    Just Joined!
    Join Date
    Dec 2007
    Posts
    1

    script using awk - products/sales

    Hey folks. I will e very upfront and say i am NOT a good UNIX script writer at ALL. I have to work on a project that will take information from 3 different date files (sales, associates, and products) and find the total sales per each associate. The files look something like this:

    products: (product ID, name, price item)
    % cat products
    103:sway bar:49.99
    101ropeller:104.99
    104:fishing line:0.99
    ...
    108:wheel:49.99
    111:lock:31.00
    102:trailer hitch:97.95

    sales: (product ID,num. sold, date sale, associate ID)
    % cat sales
    110,1,01:02:2007,22
    110,2,02:02:2007,23
    109,1,03:03:2006,24
    104,2,03:02:2007,24
    ...
    104,2,05:03:2007,24
    112,1,05:03:2007,23
    104,9,05:03:2007,21

    associates: (associate ID, name, salary, position)
    % cat associates
    21/John Doe/39000/Clerk
    22/George Bush/99000/President
    23/Susan Worker/44000/Manager
    24/Fast Buck/21000/Stock Boy
    25/Hillary Clinton/99000/Candidate
    26/Dennis Miller/88000/Commedian

    The output needs to come out something like:
    $ ./report.sh
    Name Position Sales Amount
    ========================================
    Fast Buck Stock Boy 2712.77
    George Bush President 1059.67
    Susan Worker Manager 399.52
    John Doe Clerk 284.74
    Hillary Clinton Candidate 151.00
    Dennis Miller Commedian 2.97

    I have attempted something that looks like this: (note i get errors and it wont work, but hopefully you see what im getting at, and that i have attempted something!).


    Code:
    productSales=()
    i=1
    while (i < 10)
    {
            count = 21
            if ($4 -lt count)
            ${productSales [$1]} += $2
            i++
    }
    I just dont understand how i can use awk to sort through 3 different files and then have some sort of connection between the three - say i WERE able to calculate something like:
    employeeID 21
    product#101 sold = 12
    product#110 sold = 2

    How could i get the information from the 'product' file so that i could then take
    employeeID 21 sales (in some sort of variable, maybe array? empID[21]?)
    and do prod#101 = 12
    12 * price = X
    prod#110 = 2
    2 * price = X
    total +=price

    If someone could just throw me a snip of code/script that will get me going - i know exactly how i want to do it - but i cant seem to put together 2+3 to make 5!

    I just started out with UNIX - i have a solid background in C++ so this is why a new language is tough not to confuse with the old stuff!

    Any ideas? Help? Comments?

  2. #2
    Linux Engineer RobinVossen's Avatar
    Join Date
    Aug 2007
    Location
    The Netherlands
    Posts
    1,422
    Bash Is confusing for Solid C++ coders I have problems with it aswell.
    a If uses [] instead of () in Bash and a while uses somehting like do and weird stuff. It might be easyer if you just write it in C++ And compile it for Linux. You also might want to Write it in Perl.

    Sorry I cant be a real help.
    I am Sure WJE_LJ (or whats his name, sorry I cant remember) can help you
    New Users, please read this..
    Google first, then ask..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...