Download as odt, pdf, or txt
Download as odt, pdf, or txt
You are on page 1of 3

Assignment

---------------------------------------------------------------------------------------------------------------------
Write suitable command to perform following task
a) display only the 3rd line from the file Emp.txt
Sol:- $ sed -n '1,3p' Emp.txt
Output Screenshot

b) insert the text Additional line between lines 2 and 3 in the file Emp.txt;
Sol:- $ sed '2a New line' Emp.txt
OR
$ sed '3i New line' Emp.txt
Output Screenshot

c) display the lines 4-10 from the file people.txt;


Sol:- $ sed -n '4,10p' People.txt
Output Screenshot

d) display the file Emp.txt except the lines 4-10;


Sol:- $ sed -n '4,10!p' People.txt
Output Screenshot
e) display from the file Emp.txt the lines starting with the number;
Sol:- $ sed -n '/^[0-9]/p' Emp.txt
Output Screenshot

f) display from the file Emp.txt the lines containing the strings dasgupta or sengupta;
Sol:- $ sed -n -e '/dasgupta/p' -e '/sengupta/p' Emp.txt
Output Screenshot

g) replace the string director by Epmloyee in the data from the file Emp.txt ; save the output
in the file Emp.txt;
Sol:- $ sed -i 's/director/Employee/g' Emp.txt
Output Screenshot

h) Display the name, id and department of employees whose salary is more then 5000
Sol:- $ awk -F \| '{if($4>5000)print}' Emp.txt
Output Screenshot
i) display from the file /etc/passwd the lines containing the string root; save the output in the
file root.txt;
Sol:- # sed -n '/root/p' /etc/passwd >root.txt
Output Screenshot

j) display from the file /etc/passwd the lines beginning with the string abc.
Sol:- # sed -n '/^[abc]/p' /etc/passwd
Output Screenshot

You might also like