awk programming- accepts condition from user


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk programming- accepts condition from user
# 1  
Old 08-28-2017
awk programming- accepts condition from user

I have an assignment, need your help to complete it. I am trying as well from my end but need help to complete.

emp.csv (contains emp details, say 5k records)

Code:
empid,ename,sal,comm

100,Patrick,75000,10

200,Lisbon,80000,5

300,Van,50000,null

400,Wayne,65000,2

500,Kimball,70000,7

600,Luther,72000,null

Q1. Read the emp.csv file using awk.

Q2. Calculate revised salary of all employees.

a) Display output on screen

b) Redirect output to a file called sample1.csv

Hint- Revised sal=sal+ (sal*comm)

If comm is null, assume comm=0 so, revised sal=sal

Q3. Displays output based on condition asked.

Prompts the user with a msg:-

Enter the condition

eg- We have to enter required condition say, sal > 70000 and comm is null

a) Display first 50 records (desc order of revised salary) on screen

b) Redirect output of all employees to file sample2.csv

Please do help me.

I am able to read the emp.csv using awk and I am trying the other questions from my end.

Thanks in advance!

Last edited by Don Cragun; 08-28-2017 at 04:34 AM.. Reason: Add CODE and ICODE tags.
# 2  
Old 08-28-2017
Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in the homework & coursework forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

If you did not post homework, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

If condition on awk

Hi All, Would you guys help me? I have a file that consists of several unstructured fields. in this file I will take the code field and count_berry field. but the position of the count_berry field is always changing.the column for code is always structured, which is found in column 6 I have... (4 Replies)
Discussion started by: kivale
4 Replies

2. Shell Programming and Scripting

If Condition in awk

Hi All, I have the below Input: 1 700 1200 400 1300 2 2000 1000 2000 1500 600 3 1400 200 1000 1000 1200 4 1300 500 600 200 I want to modify the field 5 and field 4 as below. If value in field 5 is null then value of field 4 should be in field 5. and then the value of... (12 Replies)
Discussion started by: am24
12 Replies

3. Shell Programming and Scripting

awk condition

Hi Gurus, one of my current script, there is awk statement as below: awk '{a=a?a" "$3:$3}END{for (i in a) print i,a}' I don't understand what's "{a=a?a" "$3:$3}" mean? can anybody give me a brief explaination. thanks in advance. (3 Replies)
Discussion started by: ken6503
3 Replies

4. Shell Programming and Scripting

awk programming -Passing variable to awk for loop

Hi All, I am new to AWK programming. I have the following for loop in my awk program. cat printhtml.awk: BEGIN -------- <some code here> END{ ----------<some code here> for(N=0; N<H; N++) { for(M=5; M<D; M++) print "\t" D ""; } ----- } ... (2 Replies)
Discussion started by: ctrld
2 Replies

5. Shell Programming and Scripting

HELP with AWK one-liner. Need to employ an If condition inside AWK to check for array variable ?

Hello experts, I'm stuck with this script for three days now. Here's what i need. I need to split a large delimited (,) file into 2 files based on the value present in the last field. Samp: Something.csv bca,adc,asdf,123,12C bca,adc,asdf,123,13C def,adc,asdf,123,12A I need this split... (6 Replies)
Discussion started by: shell_boy23
6 Replies

6. Shell Programming and Scripting

awk if condition help

Hi, I need little help with awk's if condition statement. I have following code: $ ssh myRemotehost 'ps ww -fu tomcat ' | awk ' { if ($1 == "tomcat") print "tomcat (pid " $2 ") is running... "; else print "tomcat stopped or dead" }' Prints: tomcat stopped or dead tomcat (pid 12345) is... (6 Replies)
Discussion started by: davidtd
6 Replies

7. Shell Programming and Scripting

Web Page that Accepts Email and Stores it to Disk

Hello there, So I have the below code that shows up OK on a web page. The problem I have is that, when a user enters his/her email address and hits submit, I want the provided email address to be stored on my local server. This should be simple but I have no idea how to do it. This is the... (3 Replies)
Discussion started by: SkySmart
3 Replies

8. Shell Programming and Scripting

Script that accepts user input - Suggestions

Hi, I have a series of BASH shell scripts that process data. All of the scripts are controlled by a "master" script, where users specify their processing parameters. The sub-scripts, and the order they are called, depend on the values of these user-specified processing parameters. This method... (1 Reply)
Discussion started by: msb65
1 Replies

9. Shell Programming and Scripting

awk and condition help

Hi... i just want to write a script for the follwing command "display status" and the normal output is... AN100> display status 12.13.2006 12:03:25 AN-2000-1 CC NOT PRESENT 16.50.80.49 status: Status for PACKET GLI A in the TOP / LEFT shelf of frame 0: status: The current active LAN is... (5 Replies)
Discussion started by: gini
5 Replies

10. Shell Programming and Scripting

Send email to user when condition met

Hi all, I plan to write a shell script to inform users on their task when certain condition met. example: If a then email user on action a else email user on action b. I'm pretty new in scripting, appreciate any suggestions. Thanks. (4 Replies)
Discussion started by: *Jess*
4 Replies
Login or Register to Ask a Question