Professional Documents
Culture Documents
Linux 7
Linux 7
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
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