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

Assignment 6

Date of Allotment: 31/03/2022 Date of Submission: 02/04/2022


------------------------------------------------------------------------------------------------------------------------
Create a file which contains following information.
Model:Company:Price:Camera:4G
IPhone4:Apple:1000$:Yes:Yes
Galaxy:Samsung:900$:Yes:No

Optimus:LG:800$:Yes:Yes
Sensation:HTC:400$:Yes:No

Iphone4S:Apple:1100$:Yes:Yes

N9:Nokia:400$:Yes:Yes
Note4:Xiomi:300$:Yes:Yes

Write command to perform the following task-


Q1. to delete first line from the above file.
Sol:- $ sed '1d' mobile.txt
Output Screenshot

Q2. to delete last line from the above file.


Sol:- $ sed '$d' mobile.txt
Output Screenshot
Q3. to display the details of the mobiles which supports 4G.
Sol:- $ sed -n 's/Yes/Yesss/2p' mobile.txt
Output Screenshot

Q4. to delete the blank lines.


Sol:- $sed '/^$/d' mobile.txt
Output Screenshot

Q5. to delete the details of Apple mobiles.


Sol:- $ sed '/Apple/d' mobile.txt
Output Screenshot
Q6. to replace the company name from Apple to Microsoft.
Sol:- $ sed 's/Apple/Microsoft/g' mobile.txt
Output Screenshot

Q7. to replace the second occurrence of Apple with Microsoft.


Sol:- $ sed 's/Apple/Microsoft/1' mobile.txt
Output Screenshot

Q8. to change delimiter “:” with “|”.


Sol:- $ sed 's/:/|/g' mobile.txt
Output Screenshot
Q9. to add a new line before the line where where LG is found.
Sol:- $ sed '/LG/ i shubham' mobile.txt
Output Screenshot

Q10. to display the model name and price.


Sol:- $ cut -d \: -f 1,3 mobile.txt
Output Screenshot

Q11. Count the total number of Space lines?


Sol:-
$ sed -n '/:/!=' mobile.txt OR $ sed -n '/^$/=' mobile.txt
# Display the number line Spacing with line number
OR
$ sed -n '/:/!=' mobile.txt | wc -l OR $ sed -n '/^$/=' mobile.txt | wc -l
# Number of Space linse
Output Screenshot

You might also like