Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
130 views

Linux and Shell Programming Lab Work

Here are the steps to create two files starting with 'RA' with default permission 655: 1. Create the first file: touch RAfile1 2. Check the permission: ls -l RAfile1 3. Create the second file: touch RAfile2 4. Check the permission: ls -l RAfile2 The permission of both the newly created files is -rw-r--r-- as expected. 4. Find the files which start with letter 'RA' and change those files name by using find command. Department of Computer Science (Faculty of Science), Sri Sri University, Cuttack Page | 28

Uploaded by

BANTY
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
130 views

Linux and Shell Programming Lab Work

Here are the steps to create two files starting with 'RA' with default permission 655: 1. Create the first file: touch RAfile1 2. Check the permission: ls -l RAfile1 3. Create the second file: touch RAfile2 4. Check the permission: ls -l RAfile2 The permission of both the newly created files is -rw-r--r-- as expected. 4. Find the files which start with letter 'RA' and change those files name by using find command. Department of Computer Science (Faculty of Science), Sri Sri University, Cuttack Page | 28

Uploaded by

BANTY
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 127

Sri Sri University,

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

2 Assignment-2 21-24 24th July,2020

3 Assignment-3 25-28 25th July,2020

4 Assignment-4 29-32 31st July,2020

5 Assignment-5 33-37 7th August,2020

6 Assignment-6 38 8th August,2020

7 Assignment-7 39-42 14th August,2020

8 Assignment-8 43-44 17th August,2020

9 Assignment-9 45-49 19th August,2020

10 Assignment-10 50-54 24th August,2020

11 Assignment-11 55-67 26th August,2020

12 Assignment-12 68-78 31st August,2020

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 2

CONTENT
Experiment Page
Name of the experiment Date of performance Remarks
Number number

13 Assignment-13 79-89 2nd September.2020

14 Assignment-14 90-94 7th September.2020

15 Assignment-15 95-99 9th September.2020

16 Assignment-16 100-102 14th September.2020

17 Assignment-17 103-105 16th September.2020

18 Assignment-18 106-110 21st September.2020

19 Assignment-19 111-114 23rd September.2020

20 Assignment-20 115-119 28th September.2020

21 Assignment-21 120 30th September.2020

22 Assignment-22 121 5th October,2020

23 Assignment-23 122 7th October,2020

24 Assignment-24 123 12th October,2020

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 3

CONTENT
Experiment Page
Name of the experiment Date of performance Remarks
Number number

25 Assignment-25 124 14th October,2020

26 Assignment-26 125-126 19th October,2020

27 Assignment-27 127 21st October,2020

28 Assignment-28 128-129 2nd November,2020

29 Assignment-29 130-133 11th November,2020

30 Assignment-30 134-135 16th November,2020

Name- Banty Kumar Parida

Roll No.- FOS\BCS\2018-21\015

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Assignment – 1
Question-

1. Practice "ls" command with all the options.

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>

5. Copy the contents of a file to another and Rename it and display

Outputs-

1) ‘ls’ command with all options-

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack

2) Difference between "who" and "who am I" command with output –


‘Who am I’ command ‘Prints the user name associated with the current effective user ID.’
And
‘Who’ command ‘Print information about users who are currently logged in.’
Output-

Department of Computer Science (Faculty of Science),


S
r
i

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.

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 19

4) Create the following tree structure. SSU - FOS - DOCS - 5thCS - <Name>

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 20

5) Copy the contents of a file to another and Rename it and display -

Name- Banty Kumar Parida

Roll No.- FOS\BCS\2018-21\015

Date- 17th July, 2020

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 21

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.

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 22

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.

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 23

4. Change the permission of the file new text to 666 using letter.

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 24

5. Delete empty files from one directory in one shot using find co mmand.

Name- Banty Kumar Parida

Roll No.- FOS\BCS\2018-21\015

Date -24th July, 2020

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 25

Assignment – 3
Question-

1. Compare two files using comm command.


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.

Outputs-

1. Compare two files using comm command.

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 26

2. Compare two files using diff command. Change the two files accordingly make
the two files same.

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 27

3. Create two files which start with 'RA' with default permission 655.

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 28

4. Find the files which start with letter 'RA' and change those files name by using
find command.

Name- Banty Kumar Parida

Roll No.- FOS\BCS\2018-21\015

Date – 25th July, 2020

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 29

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.

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 30

2. If the fields of the file separated by '|' then display half of the fiel ds using cut
command.

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 31

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.

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 32

5. Display all non-repeated lines of a file using uniq command.

Name- Banty Kumar Parida

Roll No.- FOS\BCS\2018-21\015

Date – 31st July, 2020

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 33

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.

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 34

2. Count the number of occurrences of three specific string from a file and display
their line number.

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 35

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

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 36

Examples-

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 37

Name- Banty Kumar Parida

Roll No.- FOS\BCS\2018-21\015

Date – 7th August, 2020

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 38

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 .

2. Search a pattern from a file which does not contain F a nd S.

Name- Banty Kumar Parida

Roll No.- FOS\BCS\2018-21\015

Date – 8th August, 2020


Department of Computer Science (Faculty of Science),
Sri Sri University, Cuttack
Page | 39

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".

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 40

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.

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 41

4. Write a short command of all the above three command using alias.

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 42

5. Write a command in crontab which run every day at 08:30 AM.

Name- Banty Kumar Parida

Roll No.- FOS\BCS\2018-21\015

Date – 14th August, 2020


Department of Computer Science (Faculty of Science),
Sri Sri University, Cuttack
Page | 43

Assignment – 8
Question-

1. Write command to delete multiple spaces to a single space.


2. Write command to replace '{}' to '()' .
3. Write the alias command of the above two command.

Outputs-

1. Write command to delete multiple spaces to a single space.

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 44

2. Write command to replace '{}' to '()' .

3. Write the alias command of the above two command.

Name- Banty Kumar Parida

Roll No.- FOS\BCS\2018-21\015

Date – 17th August, 2020

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 45

Assignment – 9
Question-

1. Write a command to count the occurrence of a word in a file.


2. Write a command to install crontab/<any application> in your system.
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.

Outputs-

1. Write a command to count the occurrence of a word in a file.

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 46

2. Write a command to install crontab/<any application> in your system.

3. Write a command to search for files that were modified in the last 7 days under
your current directory.

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 47

4. Write a command to search for files that have all permissions under your
current directory.

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 48

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 49

5. Write a command to sort all lines of a file with a specific field of the file.

Name- Banty Kumar Parida

Roll No.- FOS\BCS\2018-21\015

Date – 19th August, 2020

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 50

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.

2. Difference between grep -R and grep -r with example.

1.Grep -r

● Stands for --recursive


● Read all files under each directory, recursively, following symbolic links only if they are
on the command line.
2. Grep -R

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 51

● Stands for --dereference-recursive


● Read all files under each directory, recursively.
Example-

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 52

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.

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 53

5. Write a command to remove a particular package using dpkg, apt-get and


aptitude.

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 54

Name- Banty Kumar Parida

Roll No.- FOS\BCS\2018-21\015

Date – 24th August, 2020

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 55

Assignment – 11
Question-

1. Redirect all file information present on your current directory to a file.


2. Open the above file using vi editor and do the following operation
a) Delete first character of all the lines.
b) Move 2-3 lines and put in 6 th line.
c) Copy 2-3 lines and put after 6th line.
d) Write the above changes to a new file.
3. Difference between ":1,5 w >> <Filename> and :1,5 w <Filename>"

Outputs-

1) Redirect all file information present on your current directory to a file.

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 56

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 57

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

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 58

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 59

b) Move 2-3 lines and put in 6th line.

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 60

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 61

c) Copy 2-3 lines and put after 6th line.

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 62

d) Write the above changes to a new file.

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 63

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 64

3) Difference between ":1,5 w >> <Filename> and :1,5 w <Filename>"


1,5 w>> <filename> -appends line 1-5 to the file
EXAMPLE

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 65

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 66

1,5 w <filename> -writes only line 1-5 to the file

EXAMPLE

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 67

Name- Banty Kumar Parida

Roll No.- FOS\BCS\2018-21\015

Date – 26th August, 2020

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 68

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.

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 69

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 70

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 71

2. Open a file using vi do the following action


a) Replace all occurrences of . with ; from first line to last line.

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 72

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 73

b) Replace all occurrences of stating space of a word with < and ending space of a
word with > from first line to last line.

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 74

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 75

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 76

c) Rename the filename with .xml file.

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 77

3. Open a file using vi and copies from line-1 to line-7 and write in a new file.

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 78

4. Open a file using vi and copies from line-10 to line-15 and append in to above file.

Name- Banty Kumar Parida

Roll No.- FOS\BCS\2018-21\015

Date – 31st August, 2020


Department of Computer Science (Faculty of Science),
Sri Sri University, Cuttack
Page | 79

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-

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 80

1. Open a file using vi and replace four occurrences of string -1 to string-2 from
last line using vi editor command.

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 81

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 82

2. Open a file using vi do the following action.


a) Replace all occurrences of space with ; from first line to last line .

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 83

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 84

b) Those lines which start with same word need to be replaced with a single l

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 85

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 86

c) Rename the filename with .csv file.

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 87

3. Open a file using vi and moves from line-1 to line-7 and write in a new file.

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 88

4. Open a file using vi and moves from line-10 to line-15 and append in to above
file.

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 89

5.
Name- Banty Kumar Parida

Roll No.- FOS\BCS\2018-21\015

Date –2nd September, 2020

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 90

Assignment – 14
Question-

Gautama Buddha, the founder of Buddhism gave a strategic blow to Brahmanism. He


freed the common people from the Yoke of polytheism, ritualistic practices and false
dogmas. He became the liberator and by his preaching’s eradicated the darkness and
thus became the ‘Light of Asia’.

Do the following using vi editor command.

1. Separate the above paragraph and represent as a single line in vi editor.


2. Apply Lord Gautama Buddha instead of Gautama Buddha and He.
3. Replace all ' to ".

Outputs-

1. Separate the above paragraph and represent as a single line in vi editor.

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 91

2. Apply Lord Gautama Buddha instead of Gautama Buddha and He.

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 92

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 93

3. Replace all ' to ".

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 94

Name- Banty Kumar Parida

Roll No.- FOS\BCS\2018-21\015

Date –7th September, 2020

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 95

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 -

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 96

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.

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 97

2. Write some lines of a file in to another file using sed command.

3. Give an example of sed command with action 'c'.

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 98

4. Give an example of sed command with action ' i '.

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 99

5. Give an example of sed command with action 'a'

Name- Banty Kumar Parida

Roll No.- FOS\BCS\2018-21\015

Date –9th September, 2020

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 100

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.

2. Repeat the above question with multiple words in a single command .

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 101

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.

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 102

5. Change a line which contain a particular word using sed command.

Name- Banty Kumar Parida

Roll No.- FOS\BCS\2018-21\015

Date –14th September, 2020


Department of Computer Science (Faculty of Science),
Sri Sri University, Cuttack
Page | 103

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.

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 104

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.

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 105

4. Print all line number of a file using sed command.

Name- Banty Kumar Parida

Roll No.- FOS\BCS\2018-21\015

Date –16th September, 2020

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 106

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.

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 107

2. What are the options used in awk command with explanation.


a. -F fs -> Used to specify a file separator
Example-

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 108

b. -f filename ->To specify a file that contains awk script.

Example-

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 109

c. -v var = variable ->To declare a variable.

Example-

3. Why awk is so powerful than other commands of Linux. Explain with 2 -3 points.

AWK provides us with advantages like-

● 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.

• Mawk is a very fast AWK implementation by Mike Brennan based on a


bytecode interpreter.

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 110

• Libmawk is a fork of mawk, allowing applications to embed multiple parallel


instances of awk interpreters.
• Gawk (GNU awk) is another free-software implementation and the only
implementation that makes serious progress implementing
internationalization and localization and TCP/IP networking. It was written
before the original implementation became freely available.
• BWK awk, also known as nawk, refers to the version by Brian Kernighan. It has
been dubbed the "One True AWK" because of the use of the term in
association with the book that originally described the language and the fact
that Kernighan was one of the original authors of AWK.

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.

Name- Banty Kumar Parida

Roll No.- FOS\BCS\2018-21\015

Date –21st September, 2020

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 111

Assignment – 19
Question-

1. Give an example of system variable NR using AWK Command.


2. Give an example of system variable FS using AWK Command.
3. Give an example of system variable OFS using AWK Command.
4. Give an example of system variable ARGC using AWK Command.
5. Give an example of system variable ARGV using AWK Command.

Outputs-

1. Give an example of system variable NR using AWK Command.

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 112

2. Give an example of system variable FS using AWK Command.

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 113

3. Give an example of system variable OFS using AWK Command.

4. Give an example of system variable ARGC using AWK Command.

5. Give an example of system variable ARGV using AWK Command.


• With ARGV [ i ]-

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 114

• With ARGV [ i+1 ]

Name- Banty Kumar Parida

Roll No.- FOS\BCS\2018-21\015


Date –23rd September, 2020

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 115

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.

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 116

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-

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 117

• Subtraction Operator-

4. Implement any two logical operator on fields of a file and display it using AWK.
• ‘||’ Operator-

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 118

• ‘&&’ Operator-

5. Implement any two relational operator on fields of a file and display it using
AWK.
• ‘<’ Operator-

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 119

• ’>’ Operator-

Name- Banty Kumar Parida

Roll No.- FOS\BCS\2018-21\015

Date –28th September, 2020

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 120

Assignment – 21
Question-

1. Implement sqrt() using AWK.


2. Implement index() using AWK.
3. Implement substr() using AWK.
4. Implement tolower() using AWK.
5. Implement toupper() using AWK.

Outputs-

1. Implement sqrt() using AWK.


2. Implement index() using AWK.
3. Implement substr() using AWK.
4. Implement tolower() using AWK.
5. Implement toupper() using AWK.

The Below Image Contains all the Outputs along with program from Question 1 -Question 5.

Name- Banty Kumar Parida

Roll No.- FOS\BCS\2018-21\015

Date –30th September, 2020

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 121

Assignment – 22
Question-

1. Implement int() of awk.


2. Implement log() of awk.
3. Implement sin() of awk
4. Implement cos() of awk.
5. Implement split() of awk().

Outputs-

1. Implement int() of awk.


2. Implement log() of awk.
3. Implement sin() of awk
4. Implement cos() of awk.
5. Implement split() of awk().
The Below Image Contains all the Outputs along with program from Question 1 -Question 5.

Name- Banty Kumar Parida

Roll No.- FOS\BCS\2018-21\015

Date – 5th October, 2020

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 122

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.

Name- Banty Kumar Parida

Roll No.- FOS\BCS\2018-21\015

Date – 7th October, 2020


Department of Computer Science (Faculty of Science),
Sri Sri University, Cuttack
Page | 123

Assignment – 24
Question-

1. Find a matched string and print matched line using AWK Script.

Outputs-

• AWK Script to Find a matched string and print matched line.

Name- Banty Kumar Parida

Roll No.- FOS\BCS\2018-21\015

Date – 12th October, 2020

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 124

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.

Name- Banty Kumar Parida

Roll No.- FOS\BCS\2018-21\015

Date – 14th October, 2020

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 125

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.

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 126

2. Take two file from user , show the number of lines of each file and display
which file is having highest number of lines.

Name- Banty Kumar Parida

Roll No.- FOS\BCS\2018-21\015

Date – 19th October, 2020

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 127

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.

Name- Banty Kumar Parida

Roll No.- FOS\BCS\2018-21\015

Date – 21st October, 2020

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 128

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.

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 129

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.

Name- Banty Kumar Parida

Roll No.- FOS\BCS\2018-21\015

Date – 2nd November, 2020

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 130

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.

Step 1 - Contents of Shell Script Code and Files.

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 131

Step 2- Executing The Shell Script Command with 2 files as argument.

Step 3- Outputs of the both file

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 132

Step 4- Executing the Shell Script with one file as argument.

Step 5- Output of the file

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 133

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.

Name- Banty Kumar Parida

Roll No.- FOS\BCS\2018-21\015

Date – 11th November, 2020

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 134

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-

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack
Page | 135

OUTPUT-

Name- Banty Kumar Parida

Roll No.- FOS\BCS\2018-21\015

Date – 16th November, 2020

---------------------xxxxxxxxxxxxxxxxx---------------------

Department of Computer Science (Faculty of Science),


Sri Sri University, Cuttack

You might also like