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

Linux Command Ass

The document provides solutions to shell scripting problems involving commands like ls, cut, sort, uniq, and tr to manipulate text file data. It also includes shell scripts to calculate marks and percentages, simple interest, print system information, and display a calendar for a given month and year by reading user input. Solutions demonstrate using commands like head, tail, nl, cut, sort, uniq, and tr to select, arrange, and transform parts of files. Shell scripts print output to the terminal and use variables to read input and perform calculations.

Uploaded by

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

Linux Command Ass

The document provides solutions to shell scripting problems involving commands like ls, cut, sort, uniq, and tr to manipulate text file data. It also includes shell scripts to calculate marks and percentages, simple interest, print system information, and display a calendar for a given month and year by reading user input. Solutions demonstrate using commands like head, tail, nl, cut, sort, uniq, and tr to select, arrange, and transform parts of files. Shell scripts print output to the terminal and use variables to read input and perform calculations.

Uploaded by

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

Linux & Shell Programming 3

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