0% found this document useful (0 votes)
91 views4 pages

UNIX Assignments: Day 3

1. The document provides assignments on the sed and awk commands including examples of problems to solve using sample data. Problems include substituting delimiters, inserting/extracting lines, replacing patterns, sorting, and generating reports. 2. Awk assignments include calculating averages, generating logs and reports, sorting records, and filtering data. Sample input and output formats are provided. 3. Instructions are given to generate payroll slips and department reports by passing parameters to awk scripts using sample mast files. Tasks include sorting, filtering, calculations, and formatted output.

Uploaded by

Ayushman Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
91 views4 pages

UNIX Assignments: Day 3

1. The document provides assignments on the sed and awk commands including examples of problems to solve using sample data. Problems include substituting delimiters, inserting/extracting lines, replacing patterns, sorting, and generating reports. 2. Awk assignments include calculating averages, generating logs and reports, sorting records, and filtering data. Sample input and output formats are provided. 3. Instructions are given to generate payroll slips and department reports by passing parameters to awk scripts using sample mast files. Tasks include sorting, filtering, calculations, and formatted output.

Uploaded by

Ayushman Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

UNIX Assignments: Day 3

Concept: SED, Awk

Objective: At the end of the assignment, participants will be able to understand and
implement:
• Sed
• Awk

Problems:

Assignemnts on “sed” command

EmpData(Sample Database)

1122|j.b. saxena |g.m. |account |12/12/52|6000


2233|n.k. gupta |d.g.m |sales |31/12/40|9000
4545|anil agarwal |director |account |06/07/47|7500
5656|lalit choudhury |executive|marketing|07/09/50|5000
1265|chanchal singhvi|g.m. |admin |12/09/63|6000
0110|shyam saksena |chairman |marketing|12/12/43|8000
5566|jai sharma |director |account |23/12/89|7000
7733|jayant |d.g.m |sales |29/02/70|6000

1. From the above database substitute the delimiter of first 3 lines with “ : “
2. From the above database substitute the delimiter with “ : ”
3. Insert the string “ PSL Employees” in the first line.
4. Store the lines pertaining to the directors, d.g.m and g.m into three separate files.
5. Using address store first 4 lines into a file Empupdate.
6. Find the pattern “account” in the database and replaces that with “accounts”.
7. Select those lines which do not have a pattern “g.m”.
8. Insert a blank line after every line in the database.

Assignemnts on “AWK” command

1. Consider the results are stored in following format:

EmpID Name Subject Marks(/50)


E001 Nilesh Unix 30
E002 Nilesh DSA 20
Like these you have 10 records ( 5 of DSA and 5 of Unix)
Calculate the avg score secured in Unix and DSA and the first 2 topers in Unix and DSA each.

2. Write a script to get the report of the users logged on to the System in the following formats.
(Records should be sorted on logging time.)
Header must include company name and Date
Records in the format
Username Logged-in-time Terminal
Tailor should include total number of the users logged in.

3. Consider a text file containing the records (colon separated fields) in the format:
EmpName:EmpId:Subject:ObtMarks:TotMarks:Result

Write a script to get the result of “UNIX” Subject in the format (Considering the data file has
TotMarks=50 for UNIX)

EmpName:ObtMark:MarksOutof35

The header of the report must contain total marks and the tailor must specify the percentage
result for that subject.
Also generate another summary result containing total number of participants appeared, total
number of participants passed, and Name of the participants ranked Ist IInd, IIIrd with their
total score.

4. Create an emp_mast and dept_mast files containing following details,

empno:name:job:deptno
deptno:deptname
empno:basic:hra:conveyance:medical:prof. tax: PF:TDS

Generate the pay slip as shown below by passing the empno as parameter to the awk script.

Empno 1001
Deptno 10
Job MGR
Curency INR
-----------------------------------------------------------------------------------------------
Earnings
-----------------------------------------------------------------------------------------------
BASIC 10,000.00
HRA 4,000.00
CONVEYANCE 9,600.00
MEDICAL 5,000.00
-----------------------------------------------------------------------------------------------
Total Earnings : 28,000.00
-----------------------------------------------------------------------------------------------
Deductions
-----------------------------------------------------------------------------------------------
PF 1200.00
PROF_TAX 200.00
TDS 1600.00
-----------------------------------------------------------------------------------------------
Net Pay : 25000.00
-----------------------------------------------------------------------------------------------

Note : Check empno before passing to awk script.

5. Generate the report as given below by passing the deptno to awk script

Deptno : 10 Dname : Admin

-----------------------------------------------------
Empno Name Job
-----------------------------------------------------
1001 Ketan MGR
1002 Sachin CLERK
----------------------------------------------------

Note : Check deptno before passing to awk script

6. Consider the Arizona roaster as an input data file for this exercise. Using any combination of
the text-processing utilities listed below, write a one-line shell command that performs each of
the following tasks
(a) reports the number of players on the roster

(b) displays the roster in order by jersey number


(c) displays the roster in alphabetical order by surname
(d) displays the heaviest five players
(e) displays all players who attended Wisconsin
The Roaster is given below:-

JersyNo|Name,surname |linebackers|Weight | Date | Experience| Country


20 | Anderson, Damien |RB 5'10" | 212 | 07/17/1979 | 3 |Northwestern
30 | Ayanbadejo, Oba |FB 6'02" | 235 | 03/05/1975 | 5 |San Diego
92 | Berry,Bert |DE6'03" | 250| 08/15/1975 | 7 |NotreDame
81 | Boldin,Anquan |WR6'01" |215 | 10/03/1980 |2 | FloridaState
91 | Bryant,Wendell |DT6'04" |303| 09/12/1980 | 3 | Wisconsin
35 | Carter,Dyshod |DB5'10" |197 | 06/18/1978 |2 | Kansas State
52 | Fisher,Levar |OLB6'01" |235 | 07/02/1979 |3| NorthCarolina
11 | Fitzgerald,Larry |WR6'04" |229| 08/31/1983 |10 |Pittsburgh
63 |Garcia,Frank |G6'02" | 302| 01/28/1972|10|Washington
64 |Grace,Steven |C6'03" |295| 02/13/1979 | 3|Arizona
84 |Hamilton,Lawrence |WR6'03" |205 |08/31/1980 |2|StephenF.Austin

You might also like