Unix/Linux Go Back    


Homework & Coursework Questions Students must use and complete the template provided. If you don't, your post may be deleted! Special homework rules apply here.

Project using awk

Homework & Coursework Questions


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 04-23-2016
gamer9sam gamer9sam is offline
Registered User
 
Join Date: Apr 2016
Last Activity: 16 May 2016, 5:59 AM EDT
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Project using awk

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

1. The problem statement, all variables and given/known data:

) Your mission is to create an awk file that will report employee name, state, gross pay, taxes, and netpay in a specific format. The input file has the following fields:Name
State

Pay Rate
Hours Worked
Overtime Hours

There is math involved. The pay rate is the hourly pay rate – different for each employee. Overtime

hours are paid at 1.5 times base rate ((OT Hours * 1.5) Pay Rate). Gross Pay = (Hours Worked +
(Overtime Hours * 1.5)) * Pay Rate. Taxes are computed at 8% (0.08) for State = MO and 7% for State
= KS. Net Pay = Gross Pay - Taxes
The input file is: /home/faculty/hbecker3/projects/p5/payroll
The output should look like the following:


Code:
Name             State
------------       -- 
Sam Smith       MO
Gross Pay:      $1690
Taxes:          $135.2
Net Pay:        $1554.8

(Formatting's a bit off but it needs to be aligned)

[/FONT]
Send me the link to your awk file (I will run it with the awk -f command).


2. Relevant commands, code, scripts, algorithms:

None, just needs to be in an awk format.


3. The attempts at a solution (include all code and scripts):

Code:
Awk BEGIN{
Getline payroll
{NR > 1}
Overtime = ($5 * 1.5) * $3;
GrossPay = ($4 + (Overtime * 1.5)) * $3;
Taxes = {MO|KS , .08|.07}
NetPay = GrossPay - Taxes

{print “Name\tState\n\-------\t--”}
{printf(%.2f\n) “$1\t$2\n\Gross Pay: \tGrossPay\nTaxes: \tTaxes\nNet Pay: \tNetPay} >
project5_q2

4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

Johnson County Community College
Overland Park, KS
United States Of America
Hugo Becker
Course CIS 204 377
CRN: 12520

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

Last edited by vbe; 04-23-2016 at 11:41 AM..
Sponsored Links
    #2  
Old Unix and Linux 04-23-2016
vbe's Unix or Linux Image
vbe vbe is offline Forum Staff  
Moderator
 
Join Date: Sep 2005
Last Activity: 21 February 2017, 4:49 PM EST
Location: Switzerland - GE
Posts: 6,379
Thanks: 258
Thanked 536 Times in 498 Posts
Well what we appreciate here also is when you submit your code, that you give the output produced, and eventually your comments on it explaining what you think happened, or what you cant achieve or do not understand
We are not going to give you the solution but more, clues or help you get there...
Sponsored Links
    #3  
Old Unix and Linux 04-23-2016
gamer9sam gamer9sam is offline
Registered User
 
Join Date: Apr 2016
Last Activity: 16 May 2016, 5:59 AM EDT
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
I definitely understand, I rather just have some help.

Output:

Code:
awk: sm_p5_2.awk:6: Taxes = {MO|KS , .08|.07}
awk: sm_p5_2.awk:6:         ^ syntax error
awk: sm_p5_2.awk:6: Taxes = {MO|KS , .08|.07}
awk: sm_p5_2.awk:6:             ^ syntax error
awk: sm_p5_2.awk:9: {print “Name\tState\n\-------\t--”}
awk: sm_p5_2.awk:9:        ^ invalid char '�' in expression
awk: sm_p5_2.awk:9: {print “Name\tState\n\-------\t--”}
awk: sm_p5_2.awk:9:        ^ syntax error

Comments: I think what happened is either my calculations aren't properly formatted, or the printf can't get the information correctly.

You may want to put a comments section in the template then, just as added help. I appreciate any help I can get. And If I need to reformat my post let me know Linux

Last edited by Scrutinizer; 04-23-2016 at 12:32 PM.. Reason: code tags
    #4  
Old Unix and Linux 04-23-2016
Scrutinizer's Unix or Linux Image
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 21 February 2017, 11:05 PM EST
Location: Amsterdam
Posts: 11,242
Thanks: 467
Thanked 3,197 Times in 2,824 Posts
Hi,

The is a wrong double quote (coming from Microsoft Word?) you need to use " .

The general format in the mid section is :

Code:
condition { action }

so

Code:
{NR > 1}

makes no sense, since it is a condition, not an action
Also, in the BEGIN {} section, NR is always 0


Code:
Taxes = {MO|KS , .08|.07}

I don't know what you are doing here. If it is a string assignment then you need to use double quotes..

It is good practice to properly indent to improve readability, but also so you can easily see if the format is correct and the right number of curly braces have been used.

Look for the difference between BEGIN, END and middle section...

Last edited by Scrutinizer; 04-24-2016 at 08:53 AM..
Sponsored Links
    #5  
Old Unix and Linux 04-24-2016
gamer9sam gamer9sam is offline
Registered User
 
Join Date: Apr 2016
Last Activity: 16 May 2016, 5:59 AM EDT
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Thank you Scrutinizer for the reply!

It's coming from the email i'm passing back and forth from my professor so yes the '' should be ".

Ah, ok that makes sense with NR = 0 during the BEGIN section since that occurs before the function. Taxes is supposed to put in .08 if in MO or .07 in KS, do i need to make it an if else statement or can i just include that in the block with " ?


Code:
Awk BEGIN{
   Getline payroll}
{
    Overtime = ($5 * 1.5) * $3;
    GrossPay = ($4 + (Overtime * 1.5)) * $3;
    if (Taxes = MO)
         {tNum = .08}
    else if (Taxes = KS)
         {tNum = .07}
    NetPay = GrossPay - tNum
}
    {print “Name\tState\n\-------\t--”}
    {printf(%.2f\n) “$1\t$2\n\Gross Pay: \tGrossPay\nTaxes: \ttNum\nNet Pay      \tNetPay} >
project5_q2

I'm getting syntax errors still but no idea how to fix them.
Sponsored Links
    #6  
Old Unix and Linux 04-24-2016
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 21 February 2017, 2:28 PM EST
Location: Aachen, Germany
Posts: 10,313
Thanks: 242
Thanked 3,145 Times in 2,910 Posts
It is a bit difficult to comment on an incomplete script without any input samples, and the error msgs missing as well as some indicators where you are stuck. Which is what vbe tried to convey, I think.

A few observations on your script in post#5, as there are syntactical errors, plus semantical / logical / mathematical errors:
- awk (shell/*nix command) needs to be lower case (unless you aliased it)
- awk accepts a short program in its first parameter, so you must make sure the script is ONE string constant (e.g. by single quoting it)
- there is no input file to awk.
- getline (awk "action") needs to be lower case
- Overtime is weighted twice with its weighting factor.
- "equal" testing is done with == ; a single = is an assignment.
- wrong algorithm for the NetPay
- although pointed to by Scrutinizer, you're STILL using the char.
- your printf statement can't work: the format string is not sufficient, and the variables are not handled correctly (separate them from the format string)

And, what are you doing with the payroll variable read in the BEGIN section?
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
FINDING DUPLICATE PROJECT ( directory project ) jcdole Shell Programming and Scripting 2 09-21-2015 04:57 PM
A new project was posted on The UNIX and Linux Forums project board. Neo News, Links, Events and Announcements 0 06-08-2013 10:18 AM
awk, shell script reverse engineering app generator - project darius2 Shell Programming and Scripting 2 01-10-2009 08:13 PM
SSH doesn't pick up user's project from /etc/project kurgan Solaris 2 05-21-2008 01:52 PM



All times are GMT -4. The time now is 09:31 AM.