0% found this document useful (0 votes)
132 views

MCA 1 ST SEMESTER - 2022 Linux & Shell Programming (MCA545) Assignment - 3 Name:-Shubham Babu

This document contains the solutions to 14 questions on Linux shell programming and scripting. The questions cover commands for listing, copying, extracting, sorting, and filtering file contents. Shell scripts are provided to calculate marks and percentages, simple interest, print system information, and print a calendar for a given month and year. For each question, the command or shell script is given along with the expected output on the terminal.

Uploaded by

shubham
Copyright
© © All Rights Reserved
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
132 views

MCA 1 ST SEMESTER - 2022 Linux & Shell Programming (MCA545) Assignment - 3 Name:-Shubham Babu

This document contains the solutions to 14 questions on Linux shell programming and scripting. The questions cover commands for listing, copying, extracting, sorting, and filtering file contents. Shell scripts are provided to calculate marks and percentages, simple interest, print system information, and print a calendar for a given month and year. For each question, the command or shell script is given along with the expected output on the terminal.

Uploaded by

shubham
Copyright
© © All Rights Reserved
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 12

MCA 1 st SEMESTER – 2022

Linux & Shell Programming(MCA545)


Assignment – 3
Name:- Shubham Babu
Write suitable command for the following-

Q1. To display first 10 .c files of your working directory and save into another directory
named C_directory?
Sol
CMD :- $ ls *.c | head -10 && cp `ls *.c | head -10` C_directory
Q 2. To display last 20 files of your working directory with line number?
Sol.

CMD :- $ ls *.c | nl | tail -20

Q3. To display lines 5 to 9 from file emp.txt as you have created previously?
Sol.

CMD :- $ head -9 emp.txt | tail +5


Q 4. To display columns which contains emp_name and joining date?
Sol.
HERE I USE (-c) OPTION

CMD :- $ cut -c 4-22 emp.txt

OR
WE CAN ALSO USE( -f) and (-d)

CMD :- $ cut -d \| -f 2,3 emp.txt


5. To extract all the record which contains emp_name, designation and basic salary from your
file emp.txt and save these record into another file?
Sol.

HERE I USE (-c) OPTION

CMD :- $ cut -c 3-12,36- emp.txt


>emp2.txt ; cat emp2.txt

OR
WE CAN ALSO USE( -f) and (-d)

CMD :- $ cut -c 3-12,36- emp.txt


>emp2.txt ; cat emp2.txt
Q 6. To sort and display the record based on emp_name and also save the record into another
file?
Sol

CMD :- $ sort -k 2 emp.txt >emp2.txt ; cat


emp2.txt
Q7. To display sorted record of emp.txt file with removing duplicate lines?
Sol.

CMD :- $ sort emp.txt | uniq

Q8. To count total number of duplicate records?


Sol.

CMD :- $ sort emp.txt | uniq -c


Q 9. To display and save the records having unique salary?
Sol.

CMD:- $ sort -k 5 -u emp.txt |


uniq

Q 10. To convert the record into upper case , display and also save into another file?
Sol.

CMD:- $ tr a-z A-Z <emp.txt


Shell Scripting

Q11. Write a shell script which reads the marks in five subjects, prints total marks,
percentage?
Sol.
Vi-Editor

OUTPUT ON TERMINAL
Q12. Write a shell script to read principal amount, rate of interest and time in year. Calculate
and print the value of simple interest?
Sol.

Vi-Editor

OUTPUT ON TERMINAL
Q13. Write a shell script to print date (dd-mm-yyyy), time (hh-mm-ss), the name of your
working shell and name of terminal with suitable message?
Sol.

Vi-Editor

OUTPUT ON TERMINAL
Q14. Write a shell script to read month name and year from user and print the calendar of the
given month and year?

Sol.
Vi-Editor

OUTPUT ON TERMINAL

You might also like