You are on page 1of 4

Linux-05 Practical

Q1) Create the following file called as the geekstuff.txt and perform the following tasks.
Linux: Sysadmin ,Scripting etc.
Software
Hardware
Security (Firewall, Network, Online Security etc)
Storage
Cool gadgets and websites
Productivity (Too many technologies to explore, not much time available)
Website Design
Software Development.
Windows-Sysadmin, reboot etc.

i. Display first three lines


OUTPUT:
b11029@linux-p6l1:~> sed -n '1,3p' geekstuff.txt
Linux: Sysadmin ,Scripting etc.
Software
Hardware

ii. Display last line.


OUTPUT:
b11029@linux-p6l1:~> sed -n '$p' geekstuff.txt
Windows-Sysadmin, reboot etc.

iii. Display the third and fourth line.


OUTPUT:
b11029@linux-p6l1:~> sed -n '3,4p' geekstuff.txt
Hardware
Security (Firewall, Network, Online Security etc)

iv. Delete the last 2 records from the file.


OUTPUT:
b11029@linux-p6l1:~> cat -n geekstuff.txt
1 Linux: Sysadmin ,Scripting etc.
2 Software
3 Hardware
4 Security (Firewall, Network, Online Security etc)
5 Storage
6 Cool gadgets and websites
7 Productivity (Too many technologies to explore, not much time available)
8 Website Design
9 Software Development.
10 Windows-Sysadmin, reboot etc.
b11029@linux-p6l1:~> sed '9,10d' geekstuff.txt
Linux: Sysadmin ,Scripting etc.
Software
Hardware
Security (Firewall, Network, Online Security etc)
Storage
Cool gadgets and websites
Productivity (Too many technologies to explore, not much time available)
Website Design

v. Display lines only between 3 to 5 form above file.


OUTPUT:
b11029@linux-p6l1:~> sed -n '3,5p' geekstuff.txt
Hardware
Security (Firewall, Network, Online Security etc)
Storage

vi. Display all lines above file except 2.


OUTPUT:
b11029@linux-p6l1:~> sed -n '2!p' geekstuff.txt
Linux: Sysadmin ,Scripting etc.
Hardware
Security (Firewall, Network, Online Security etc)
Storage
Cool gadgets and websites
Productivity (Too many technologies to explore, not much time available)
Website Design
Software Development.
Windows-Sysadmin, reboot etc.

vii. Replace the word Software with the word Technology.


OUTPUT:
b11029@linux-p6l1:~> sed 's/Software/Technology/g' geekstuff.txt
Linux: Sysadmin ,Scripting etc.
Technology
Hardware
Security (Firewall, Network, Online Security etc)
Storage
Cool gadgets and websites
Productivity (Too many technologies to explore, not much time available)
Website Design
Technology Development.
Windows-Sysadmin, reboot etc.

viii. Write a command to print from fourth line till eight line.
OUTPUT:
b11029@linux-p6l1:~> sed -n '4,8p' geekstuff.txt
Security (Firewall, Network, Online Security etc)
Storage
Cool gadgets and websites
Productivity (Too many technologies to explore, not much time available)
Website Design

ix. Write a command to print the line only which matches the Pattern Sysadmin.
OUTPUT:
b11029@linux-p6l1:~> sed -n '/Sysadmin/p' geekstuff.txt
Linux: Sysadmin ,Scripting etc.
Windows-Sysadmin, reboot etc.

x. Write a command to print the 5th line which matches the pattern ‘Storage’ and next
two lines following ‘Storage’.
OUTPUT:
Method: Manually searching
b11029@linux-p6l1:~> sed -n -e '5p' -e '6,7p' geekstuff.txt
Storage
Cool gadgets and websites
Productivity (Too many technologies to explore, not much time available)
Other Method where we are matching pattern
b11029@linux-p6l1:~> sed -n -e '/Storage/p' -e '6,7p' geekstuff.txt
Storage
Cool gadgets and websites
Productivity (Too many technologies to explore, not much time available)

Q2)Create a file Seniors as shown below:

2233| a.k.shukla| g.m|Sales|12/12/52|6000


9876|Jai Sharma|Director|Production|03/12/50|7000
5678|Sumit Chakraborty|d.g.m|Marketing|04/09/43|6000
2365|Barun Sengupta|Director|Personnel|05/11/47|7800
5423|n.k.sengupta|Chairman|Admin|08/30/56|5400
4356|Seema desai|Hr|Sales|12/12/83|4000
i. Write a command to display all directors in Seniors<rollno> file.
OUTPUT:
b11029@linux-p6l1:~> sed -n '/Director/p' Seniors1029
9876|Jai Sharma| Director| Production|03/12/50|7000
2365|Barun Sengupta|Director|Personnel|05/11/47|7800

ii. Write a command to search all hr in Senoirs<rollno> file and give them a
Promotion as Manager.
OUTPUT:
b11029@linux-p6l1:~> sed 's/Hr/Manager/g' Seniors1029
2233| a.k.shukla | g.m | Sales |12/12/52|6000
9876|Jai Sharma| Director| Production|03/12/50|7000
5678|Sumit Chakraborty|d.g.m|Marketing|04/09/43|6000
2365|Barun Sengupta|Director|Personnel|05/11/47|7800
5423|n.k.sengupta|Chairman|Admin|08/30/56|5400
4356|Seema desai|Manager|Sales|12/12/83|4000

iii. Select all the persons present in the sales department, from Senoirs<roll_no> file
and store them in the sales file and store all the admins in a list file.
OUTPUT:
b11029@linux-p6l1:~> sed -n '/Sales/p' Seniors1029>Sales
b11029@linux-p6l1:~> cat Sales
2233| a.k.shukla | g.m | Sales |12/12/52|6000
4356|Seema desai|Hr|Sales|12/12/83|4000

b11029@linux-p6l1:~> sed -n '/Admin/p' Seniors1029>a.lst


b11029@linux-p6l1:~> cat a.lst
5423|n.k.sengupta|Chairman|Admin|08/30/56|5400

iv. Write commands to change the empno present in the Seniors<rollno> all
empnos Should begin with 2.
OUTPUT:
b11029@linux-p6l1:~> sed 's/^/2/g' Seniors1029
22233| a.k.shukla | g.m | Sales |12/12/52|6000
29876|Jai Sharma| Director| Production|03/12/50|7000
25678|Sumit Chakraborty|d.g.m|Marketing|04/09/43|6000
22365|Barun Sengupta|Director|Personnel|05/11/47|7800
25423|n.k.sengupta|Chairman|Admin|08/30/56|5400
24356|Seema desai|Hr|Sales|12/12/83|4000

You might also like