Linux and Shell Programming Lab Work
Linux and Shell Programming Lab Work
Cuttack
LINUX AND
SHELL
PROGRAMMING
LABORATORY
RECORD
BSc (Honors) Computer Science
5th Semester
Name: - BANTY KUMAR PARIDA
Registration No: - FOS\BCS\2018-21\007
Roll No: - 007
[Pick the date]
Page | 1
CONTENT
Experiment Pag
Name of the experiment Date of performance Remark
Number e
s
numb
1 Assignment-1 5-20 17th July,2020
CONTENT
Experiment Page
Name of the experiment Date of performance Remarks
Number number
CONTENT
Experiment Page
Name of the experiment Date of performance Remarks
Number number
2. Difference between "who" and "who am I" command. Writer down the output.
3. Create a file having your name and put all the information and display it. Again
append 5 more lines into it and display again.
4. Create the following tree structure. SSU - FOS - DOCS - 5thCS - <Name>
Outputs-
S
r
i
U
n
i
v
e
r
s
i
t
y
,
C
u
t
t
a
c
k
Page | 18
3) Create a file having your name and put all the information and display it. Again
append 5 more lines into it and display again.
4) Create the following tree structure. SSU - FOS - DOCS - 5thCS - <Name>
Assignment – 2
Question-
1. Create a file matter and type any two sentences in it using cat command.
2. Combine the contents of two files text and matter into another file txtmat using
cat command.
3. Change the permission of the file new text to 666 using numeric value.
4. Change the permission of the file new text to 666 using letter.
5. Delete empty files from one directory in one shot using find command.
Outputs-
1. Create a file matter and type any two sentences in it using cat command.
2. Combine the contents of two files text and matter into another file txtmat using
cat command.
3. Change the permission of the file new text to 666 using numeric value.
4. Change the permission of the file new text to 666 using letter.
5. Delete empty files from one directory in one shot using find co mmand.
Assignment – 3
Question-
Outputs-
2. Compare two files using diff command. Change the two files accordingly make
the two files same.
3. Create two files which start with 'RA' with default permission 655.
4. Find the files which start with letter 'RA' and change those files name by using
find command.
Assignment – 4
Question-
1. Display half of the contents of the file vertically using cut command.
2. If the fields of the file separated by '|' then display half of the fields using cut
command.
3. Display the two halves of the file of the above question by using paste
command.
4. Sort all the lines of a file in descending order.
5. Display all non-repeated lines of a file using uniq command.
Outputs-
1. Display half of the contents of the file vertically using cut command.
2. If the fields of the file separated by '|' then display half of the fiel ds using cut
command.
3. Display the two halves of the file of the above question by using paste
command.
Assignment – 5
Question-
1. List out all file names which contain a specific string and tar them in to a single
folder.
2. Count the number of occurrences of three specific string from a file and display
their line number.
3. Find out all the processes running in your current directory kill the process
which start with 'p'.
4. What is the basic difference between grep and egrep with example.
Outputs-
1. List out all file names which contain a specific string and tar them in to a single
folder.
2. Count the number of occurrences of three specific string from a file and display
their line number.
3. Find out all the processes running in your current directory kill the process
which start with 'p'.
4. What is the basic difference between grep and egrep with example.
-Grep –
Grep is a command that allows searching content according to the given regular expression and
displaying the matching lines .
Grep is a command that allows searching content according to the given regular expression and
displaying the matching lines.
-Egrep –
Egrep is a variant of grep that helps to search content by applying extended regular expressions to
display the machining lines
Examples-
Assignment – 6
Question-
1. Search a pattern from a file which start with F and end with S.
2. Search a pattern from a file which does not contain F and S.
Outputs-
1. Search a pattern from a file which start with F and end with S .
Assignment – 7
Question-
1. Write a command to print the lines of a file which ends with the word "end" .
2. Write command to display grep related command that you have typed before
using history.
3. Write a command which changes all small letter to capital letter of a file.
4. Write a short command of all the above three command using alias.
5. Write a command in crontab which run every day at 08:30 AM.
Outputs-
1. Write a command to print the lines of a file which ends with the word "end".
2. Write command to display grep related command that you have typed before
using history.
3. Write a command which changes all small letter to capital letter of a file.
4. Write a short command of all the above three command using alias.
Assignment – 8
Question-
Outputs-
Assignment – 9
Question-
Outputs-
3. Write a command to search for files that were modified in the last 7 days under
your current directory.
4. Write a command to search for files that have all permissions under your
current directory.
5. Write a command to sort all lines of a file with a specific field of the file.
Assignment – 10
Question-
1. Write a command to look for all files in the current directory and in all of its
subdirectories for a particular word.
2. Difference between grep -R and grep -r with example.
3. Write a command to display all the output with line number to search particular
word from the file.
4. Write a command to search a particular package using dpkg,apt-get and
aptitude.
5. Write a command to remove a particular package using dpkg,apt -get and
aptitude.
Outputs-
1. Write a command to look for all files in the current directory and in all of its
subdirectories for a particular word.
1.Grep -r
3. Write a command to display all the output with line number to search particular
word from the file.
Assignment – 11
Question-
Outputs-
2) Open the above file using vi editor and do the following operation
a) Delete first character of all the lines.
• To open VI editor - vi filename
• Press ctrl+v
• Select 1st character of all first lines
• Press x to delete
• Press :wq to close
EXAMPLE
Assignment – 12
Question-
1. Open a file using vi and replace all occurrences of string-1 to string-2 from one
particular line to another line using vi editor command.
2. Open a file using vi do the following action
a) Replace all occurrences of . with ; from first line to last line
b) Replace all occurrences of stating space of a word with < and ending space
of a word with > from first line to last line.
c) Rename the filename with .xml file.
3. Open a file using vi and copies from line-1 to line-7 and write in a new file.
4. Open a file using vi and copies from line-10 to line-15 and append in to above
file.
Outputs-
1. Open a file using vi and replace all occurrences of string -1 to string-2 from one
particular line to another line using vi editor command.
b) Replace all occurrences of stating space of a word with < and ending space of a
word with > from first line to last line.
3. Open a file using vi and copies from line-1 to line-7 and write in a new file.
4. Open a file using vi and copies from line-10 to line-15 and append in to above file.
Assignment – 13
Question-
1. Open a file using vi and replace four occurrences of string -1 to string-2 from
last line using vi editor command.
2. Open a file using vi do the following action.
a) Replace all occurrences of space with ; from first line to last line
b) Those lines which start with same word need to be replaced with a single line.
c) Rename the filename with .csv file.
3. Open a file using vi and moves from line-1 to line-7 and write in a new file.
4. Open a file using vi and moves from line-10 to line-15 and append in to above
file.
Outputs-
1. Open a file using vi and replace four occurrences of string -1 to string-2 from
last line using vi editor command.
b) Those lines which start with same word need to be replaced with a single l
3. Open a file using vi and moves from line-1 to line-7 and write in a new file.
4. Open a file using vi and moves from line-10 to line-15 and append in to above
file.
5.
Name- Banty Kumar Parida
Assignment – 14
Question-
Outputs-
Assignment – 15
Question-
1. Explain the difference between grep -v and similar command sed with example.
2. Write some lines of a file in to another file using sed command.
3. Give an example of sed command with action 'c'.
4. Give an example of sed command with action ' i '.
5. Give an example of sed command with action 'a'.
Outputs-
1. Explain the difference between grep -v and similar command sed with example.
Original context of file -
Grep -v naman names.txt->Display lines that does not matches the pattern or word.
sed -n ‘/naman/!p’ names.txt ->Displays the line that do not match with the pattern. But,
unlike grep the command to print the lines has to be given as ‘p’ or ‘!p’ ...the command
reminds the same for printing the lines that matches with pattern or do not match with the
pattern.
Assignment – 16
Question-
1. Delete all lines in between a one particular word to another particular word
using sed command.
2. Repeat the above question with multiple words in a single command.
3. Add a line before a line which contain a particular word using sed command.
4. Add a line after a line which contain a particular word using sed command.
5. Change a line which contain a particular word using sed command.
Outputs-
1. Delete all lines in between a one particular word to another particular word
using sed command.
3. Add a line before a line which contain a particular word using sed command .
4. Add a line after a line which contain a particular word using sed command.
Assignment – 17
Question-
1. Substitute one string with same string + other string using sed command.
2. Swap two string of a file using sed command.
3. Convert all occurrences of small alphabet vowel to capital alphabet vowel using
sed and tr command.
4. Print all line number of a file using sed command.
Outputs-
1. Substitute one string with same string + other string usi ng sed command.
3. Convert all occurrences of small alphabet vowel to capital alphabet vowel using
sed and tr command.
Assignment – 18
Question-
1. Print all lines of a file using both awk command and sed command.
2. What are the options used in awk command with explanation.
3. Why awk is so powerful than other commands of Linux. Explain with 2 -3 points.
4. What are the versions available in awk. Explain each version with 1-2 points.
5. What are the differences between awk and nawk. Explain with 2 -3 points.
Outputs-
1. Print all lines of a file using both awk command and sed command.
Example-
Example-
3. Why awk is so powerful than other commands of Linux. Explain with 2 -3 points.
● Validate data
● Managing small DB files
● Generating reports
● Parsing command outputs
● Parsing log files
● Can parse more than one file at a time.
And these advantages make AWK more powerful than other commands.
4. What are the versions available in awk. Explain each version with 1-2 points.
5. What are the differences between awk and nawk. Explain with 2 -3 points.
• Awk is a pattern scanning and processing language. Its name comes from the
last initials of the three authors: Alfred. V. Aho, Brian. W. Kernighan, and
Peter. J. Weinberger.
• Nawk is newer standard of awk designed to facilitate large awk programs.
This is AT&T’s version of the Awk.
•
• FNR, ARGC,ARGV, ARGIND,SUBSEP,RSTART,RLEANGTH,OFMT features are
available in Nawk but not AWK.
Assignment – 19
Question-
Outputs-
Assignment – 20
Question-
1. Search specific string related line from a file and display some fields of the line
using AWK.
2. Search a line from a file starting with a specific string and display some fields of
the line using AWK.
3. Implement any two arithmetic operator on fields of a file and display it using
AWK.
4. Implement any two logical operator on fields of a file and displa y it using AWK.
5. Implement any two relational operator on fields of a file and display it using
AWK.
Outputs-
1. Search specific string related line from a file and display some fields of the line
using AWK.
2. Search a line from a file starting with a specific string and display some fields of
the line using AWK.
3. Implement any two arithmetic operator on fields of a file and display it using
AWK.
• Addition operator-
• Subtraction Operator-
4. Implement any two logical operator on fields of a file and display it using AWK.
• ‘||’ Operator-
• ‘&&’ Operator-
5. Implement any two relational operator on fields of a file and display it using
AWK.
• ‘<’ Operator-
• ’>’ Operator-
Assignment – 21
Question-
Outputs-
The Below Image Contains all the Outputs along with program from Question 1 -Question 5.
Assignment – 22
Question-
Outputs-
Assignment – 23
Question-
1. Write down an awk script to display all the file names, link names and directory
names of a current folder.
Outputs-
• awk script to display all the file names, link names and di rectory names of a
current folder.
Assignment – 24
Question-
1. Find a matched string and print matched line using AWK Script.
Outputs-
Assignment – 25
Question-
1. Write down an awk script which display the fields of all the lines of a file.
Where the field of each line is longest among all the fields of a particular line.
Outputs-
• AWK Script which display the fields of all the lines of a file. Where the field of
each line is longest among all the fields of a particular line.
Assignment – 26
Question-
1. Take two string from user through command line and check whether they are
same or not.
2. Take two file from user , show the number of lines of each file and display
which file is having highest number of lines.
Outputs-
1. Take two string from user through command line and check whether the y are
same or not.
2. Take two file from user , show the number of lines of each file and display
which file is having highest number of lines.
Assignment – 27
Question-
1. Write a shell script which search all shell script files from your home director y,
make a new directory and move all shell script files in to this directory.
Outputs-
• Shell script which search all shell script files from your home directory, make a
new directory and move all shell script files in to this directory.
Assignment – 28
Question-
1. Write a shell script that counts total number of lines in two files supplied as
arguments to it.
2. Write a shell script that accepts two integer arguments and computes the value
of first number raised to the power of the second number.
Outputs-
1. Write a shell script that counts total number of lines in two files supplied as
arguments to it.
2. Write a shell script that accepts two integer arguments and computes the value
of first number raised to the power of the second number.
Assignment – 29
Question-
1. Write a shell script that deletes all lines containing a specified word in one or
more files supplied as arguments to it.
2. Write a shell script that counts total number of lines in each file supplied as
arguments to it.
Outputs-
1. Write a shell script that deletes all lines containing a specified word in one or
more files supplied as arguments to it.
2. Write a shell script that counts total number of lines in each file supplied as
arguments to it.
The Below Image Contains Shell Script Code , 2 files supplied as argument to the code, 1 file
supplied as argument to the code.
Assignment – 30
Question-
1. Write a Perl program which contains an hash array where key is the country
name and value is its capital of the country. Take input of all countrie s name
and its capital from the user.
Outputs-
• Write a Perl program which contains an hash array where key is the country
name and value is its capital of the country. Take in put of all countries name
and its capital from the user.
CODE-
OUTPUT-
---------------------xxxxxxxxxxxxxxxxx---------------------